# Finite complete graph of arbitrary size in Tikz

I want to present a complete graph of arbitrary finite size. This means a number of nodes which are interconnected to all other nodes. In addition I want to clearify that the number of nodes is not important. For numbers this would simply look like this:

$$1, \dots, n$$


I want to add one additional node at the side which is connected to all other nodes in the complete graph.

I am not looking for a manual how to do an exact representation in tikz which is most elegant. Those exists. I looking for a more abstract depicted which tells the viewer that this is a complete graph on the first sight. I am open to unorthodox solutions. Like a cloud of interconnected nodes with or without \dots e.g. ... Any ideas?

-
Can you make the question less technical and more TeXnical? – percusse Jul 2 '13 at 20:29
Good point! Thanks – joachim Jul 2 '13 at 20:42

Hmmm... less conventional request than it may appear. Here is a simple take on the problem. More/less nodes can be added at will.

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\foreach \x in {1,...,7}{%
\pgfmathparse{(\x-1)*360/8}
\node[draw,circle,inner sep=0.25cm] (N-\x) at (\pgfmathresult:5.4cm) [thick] {};
}
\pgfmathparse{7*360/8}
\node[circle,red] (N-8) at (\pgfmathresult:5.4cm) {\ldots};
\foreach \x in {1,...,7}{%
\foreach \y in {\x,...,7}{%
\path (N-\x) edge[ultra thin,-] (N-\y);
}
}
\foreach \y in {1,...,8}{%
\path (N-8) edge[red, very thick, loosely dotted] (N-\y);
}
\end{tikzpicture}
\end{document}


and the output:

Another variant, with a node drawn in dotted line with or without \ldots inside requires some fiddling with the above code:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[ultra thick,decoration={border,segment length=2mm,amplitude=0.3mm,angle=90}]
\foreach \x in {1,...,7}{%
\pgfmathparse{(\x-1)*360/8}
\node[draw,circle,inner sep=0.25cm] (N-\x) at (\pgfmathresult:5.4cm) [thick] {};
}
\pgfmathparse{7*360/8}
\node[draw,circle,red,inner sep=0.25cm,decorate] (N-8) at (\pgfmathresult:5.4cm) {};
\foreach \x in {1,...,7}{%
\foreach \y in {\x,...,7}{%
\path (N-\x) edge[ultra thin,-] (N-\y);
}
}
\foreach \y in {1,...,8}{%
\path (N-8) edge[red, very thick, loosely dotted] (N-\y);
}
\end{tikzpicture}
\end{document}


Of course, you can have the \ldots in the red dotted node, but you will have to set its inner sep to another value (I'd suggest 0.125cm).

## EDIT:

@JLDiaz suggested to label the nodes and the last two should be labelled $n-1$ and $n$. That sounds cool, so I decided to do just that. The trick is to replace the node drawing line in the first foreach loop with:

\node[draw,circle] (N-\x) at (\pgfmathresult:5.4cm) [thick] {\pgfmathparse{(\x==2)?"$n$":((\x==1)?"$n-1$":int(\x-2))}\pgfmathresult};


There is a conditional in it, checking for the number of the node. Since the last node to be drawn is the one with the \ldots, the first should contain $n-1$ and the second $n$, so that is what the code does. int is needed to force TikZ to print an integer, otherwise you would have something like '1.0', etc. for labels. And then there is also minimum size=3.5em for all the nodes, which makes sure the nodes that contain only a number will be as large as the one that must accommodate $n-1$ - em is chosen to scale if the font size changes.

Full code:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{tikzpicture}[ultra thick,every node/.style={minimum size=3.5em},decoration={border,segment length=2mm,amplitude=0.3mm,angle=90}]
\foreach \x in {1,...,7}{%
\pgfmathparse{(\x-1)*360/8}
\node[draw,circle] (N-\x) at (\pgfmathresult:5.4cm) [thick] {\pgfmathparse{(\x==2)?"$n$":((\x==1)?"$n-1$":int(\x-2))}\pgfmathresult};
}
\pgfmathparse{7*360/8}
\node[draw,circle,red,inner sep=0.25cm,decorate] (N-8) at (\pgfmathresult:5.4cm) {};
\foreach \x in {1,...,7}{%
\foreach \y in {\x,...,7}{%
\path (N-\x) edge[ultra thin,-] (N-\y);
}
}
\foreach \y in {1,...,8}{%
\path (N-8) edge[red, very thick, loosely dotted] (N-\y);
}
\end{tikzpicture}
\end{document}


... and ta-dah:

(Note: If I come up with something smarter, I'll edit my answer...)

-
I think the graph would benefit from the nodes being labelled. For example, start at the node at west and label it 1. Continue clockwise labelling the nodes as 2, 3, 4, 5 then it comes the node with ... on it, and the next one will be labelled $n-1$ and the last one $n$. This conveys the message that the number of actual nodes in the graph is an arbitrary $n$ and only a few ones were drawn. Perhaps the number of drawn nodes could be reduced using this approach. – JLDiaz Jul 3 '13 at 9:07
@JLDiaz: Thanks for the suggestion! Edited. :) – Count Zero Jul 3 '13 at 11:46