Drawing a Directed Complete Graph (K16) with TikZ in LaTeX

This article explores Graph Theory concepts and LaTeX TikZ coding techniques to render a Directed Complete Graph with 16 nodes ().
Introduction
In Graph Theory, a complete graph is defined as a simple graph where every pair of distinct vertices is connected by a unique edge.
When extended to a directed complete graph (or symmetric complete digraph), every pair of vertices and is connected by two opposing directed edges: one arrow pointing from to , and another pointing from to .
This article breaks down a LaTeX TikZ implementation by Quintin Jean-Noël. The code leverages nested loops, TeX counter arithmetic for circular polar positioning, and subtle curved paths (bend left and bend right) to cleanly render 240 directed edges connecting 16 nodes.
Mathematical Analysis: Complete Graph
For a directed complete graph with vertices:
- Number of Vertices ():
- Number of Unique Vertex Pairs:
- Total Directed Edges (): Since each pair has 2 anti-parallel directed edges:
- Vertex Degree:
Each vertex is connected to the remaining 15 vertices:
- Out-degree:
- In-degree:
LaTeX Source Code
Here is the complete TikZ code by Quintin Jean-Noël:
% A complete graph
% Author: Quintin Jean-Noël
\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\usetikzlibrary[topaths]
% TeX counter for precise angle calculation
\newcount\mycount
\begin{document}
\begin{tikzpicture}[transform shape]
% 1. Create First 8 Nodes (Angles: 0, 45, 90, 135, ...)
\foreach \number in {1,...,8}{
\mycount=\number
\advance\mycount by -1
\multiply\mycount by 45
\advance\mycount by 0
\node[draw,circle,inner sep=0.25cm] (N-\number) at (\the\mycount:5.4cm) {};
}
% 2. Create Second 8 Nodes with 22.5 Degree Offset (Angles: 22.5, 67.5, ...)
\foreach \number in {9,...,16}{
\mycount=\number
\advance\mycount by -1
\multiply\mycount by 45
\advance\mycount by 22.5
\node[draw,circle,inner sep=0.25cm] (N-\number) at (\the\mycount:5.4cm) {};
}
% 3. Connect All Vertex Pairs with Opposing Curved Edges
\foreach \number in {1,...,15}{
\mycount=\number
\advance\mycount by 1
\foreach \numbera in {\the\mycount,...,16}{
\path (N-\number) edge[->,bend right=3] (N-\numbera)
edge[<-,bend left=3] (N-\numbera);
}
}
\end{tikzpicture}
\end{document}Output Produced
The resulting graphical output displays a dense, symmetrical circular graph network:

Detailed Code Analysis & Logic
1. TeX Counter Arithmetic for Angular Placement
Traditional TeX loops do not support floating-point arithmetic directly inside native loop expressions. To overcome this, the author splits the 16 nodes into two passes using \newcount\mycount:
- Pass 1 (Nodes 1–8): Computes angle , producing .
- Pass 2 (Nodes 9–16): Adds a fractional offset, producing .
Each node is assigned a TikZ identifier (N-1) through (N-16) at a radial distance of .
2. Nested Loop Structure
To connect every distinct pair of nodes without duplication:
- The outer loop runs from to .
- The inner loop runs from to .
- This executes exactly iterations.
3. Edge Separation via bend left & bend right
If two opposing directed arrows are drawn as straight lines over each other, they overlap completely and hide directional detail.
- Option
edge[->,bend right=3]curves the forward arrow to the right. - Option
edge[<-,bend left=3]curves the return arrow to the left. - This subtle curvature creates a small gap between anti-parallel edges, ensuring all 240 directed arrows remain distinctly visible.
TikZ Experimentation
Try these modifications to explore further:
- Varying Vertex Count (): Try () or () for a sparser network graph.
- Distance-Based Edge Coloration: Color edges based on chord length (e.g. blue for adjacent neighbors, red for diameter chords).
- Bipartite Graph Layout: Arrange nodes in two parallel columns to render a Complete Bipartite Graph ().
Conclusion
Quintin Jean-Noël’s TikZ code provides an excellent example of how abstract Graph Theory objects can be translated into clean visual representations in LaTeX. By leveraging counter calculations and curvature options (bend), 240 directed edges are rendered automatically with precision and balance.
References
- Quintin Jean-Noël, A complete graph, TeXample.net
- Till Tantau, The TikZ and PGF Manual, v3.1.10, 2024.
- Douglas B. West, Introduction to Graph Theory, 2nd Edition, Prentice Hall.
Written by: Aan Triono
License: CC BY-SA 4.0




