# Drawing a ring of cliques in tikz-graphs

I'm about to draw a ring of cliques graph, with a custom number of nodes in the cliques and a custom number of cliques.

My first solution is to use tikz-graphs to draw the cliques, but the problem is how to tile the cliques with rotation around a center and how to add lines that connect the cliques with a path as in a)

I can draw a clique with:

\begin{tikzpicture}
\graph [nodes={draw=none, circle, fill=darkgray}, circular placement, empty nodes, n=8] { subgraph K_n [name=outer] };
\end{tikzpicture}


While, for positioning of simple nodes, something like:

\foreach \s in {22.5,112.5,202.5,292.5}
{
\node[draw, circle, rotate=\s+90,xscale=10.25,yscale=7.25] at (\s:2) {};
}


works, I don't know how to loop in this way for tikz-graphs macros.

Whi

Based on the last comment of the OP for n>=8, this attempt did not seek help from tikz-graph but define a macro for the cliques called single which takes 2 arguments #1= labels for different cliques in the ring, #2= number of cliques in the ring. Basically, this code uses scope environment to allocate the cliques in a circular manner and foreach loops are used extensively.

Code

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand\single[2]{ % #1=labels, #2= n=number of nodes
\foreach \x in {1,...,#2}{
\pgfmathsetmacro{\ang}{360/#2}
\pgfmathparse{(\x-1)*\ang}
\node[draw,fill=red,circle,inner sep=1pt] (#1-\x) at (\pgfmathresult:4cm) {};
}
\foreach \x [count=\xi from 1] in {1,...,#2}{
\foreach \y in {\x,...,#2}{
\path (#1-\xi) edge[-] (#1-\y);
}
}
}

\begin{document}
\noindent
\begin{tikzpicture}
\begin{scope}[local bounding box=scope1]
\node at (0,0){$n=4$};
\end{scope}
\foreach \s[count=\si from 0] in {0,45,90,...,360}{
\begin{scope}[shift={($(scope1) +(\s:2)$)}, scale=0.1,rotate=\s+90]
\single{\si}{4};
\end{scope}
}
\foreach \i/\j in {1/2,2/3,3/4,4/5,5/6,6/7,7/8,8/1}
\draw (\i-1)--(\j-3);
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[local bounding box=scope1]
\node at (0,0){$n=6$};
\end{scope}
\foreach \s[count=\si from 0] in {0,45,90,...,360}{
\begin{scope}[shift={($(scope1) +(\s:2)$)}, scale=0.1,rotate=\s+30]
\single{\si}{6};
\end{scope}
}
\foreach \i/\j in {1/2,2/3,3/4,4/5,5/6,6/7,7/8,8/1}
\draw (\i-2)--(\j-5);
\end{tikzpicture}

\bigskip

\noindent
\begin{tikzpicture}
\begin{scope}[local bounding box=scope1]
\node at (0,0){$n=8$};
\end{scope}
\foreach \s[count=\si from 0] in {0,45,90,...,360}{
\begin{scope}[shift={($(scope1) +(\s:2)$)}, scale=0.1,rotate=\s+90]
\single{\si}{8};
\end{scope}
}
\foreach \i/\j in {1/2,2/3,3/4,4/5,5/6,6/7,7/8,8/1}
\draw (\i-1)--(\j-5);
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[local bounding box=scope1]
\node at (0,0){$n=10$};
\end{scope}
\foreach \s[count=\si from 0] in {0,45,90,...,360}{
\begin{scope}[shift={($(scope1) +(\s:2)$)}, scale=0.1,rotate=\s+90]
\single{\si}{10};
\end{scope}
}
\foreach \i/\j in {1/2,2/3,3/4,4/5,5/6,6/7,7/8,8/1}
\draw (\i-1)--(\j-6);
\end{tikzpicture}

\end{document}

• I think this solution is the best, but just because of probable bugs in the tikz-graphs. I find this simpler to understand. Jan 20, 2015 at 9:35

This is a possible solution with two loops, one to create the graph and the second for the interconnection.

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard}

\tikzset{pic rotate/.store in=\picrotate,
pic rotate=0,
graph name/.store in=\grname,
my clique/.pic={
\graph [name separator=-,nodes={draw, circle, fill=red,rotate=\picrotate}, circular placement, empty nodes, n=8] { subgraph K_n [name=\grname] };
}
}

\begin{document}

\begin{tikzpicture}
\foreach \angle[count=\xi] in {0,45,...,360}{
\pic [graph name=\xi,pic rotate=\angle] at (\angle:5cm) {my clique};
}
\foreach \x[evaluate=\x as \previousnode using int (\x-1)] in {2,...,9}
\draw(\x-4)--(\previousnode-1);
\end{tikzpicture}

\end{document}


The result:

• Why in this script can't I change the number of nodes in the clique? It seems that over 6 I can't increase the number of nodes in the cliques. Jan 19, 2015 at 14:39
• @linello: Honestly, I don't know. It was the first time I used the new graphdrawing facilities. However, it looks strange. Do you refer to the n key within the options passed to \graph? Jan 19, 2015 at 14:59
• Yes exactly. The n key doesnt'allow to increase the size of the clique >=6 particularly in the script you posted. Jan 19, 2015 at 15:25
• @linello: But I have n=8... Jan 19, 2015 at 15:28
• A solution that does not use tikz-graph is also acceptable. Sorry for having said n=6 while actually the problem is for n>=8. Jan 19, 2015 at 16:18