# How to make a $\rho$-shaped graph for various lists of numbers as nodes?

This question is derived from this other question, where @marmot solved it nicely. However, that solution assumes the cycle will always have a number of nodes more or less like 11. When you apply that solution to a cycle with, say, 4 nodes, the cycle looks more like a square.

How could we change those arrows to present themselves more like a circle? Ideally it would look like an ellipse with radii as near as possible to the $rho$ letter, but a circle would do just fine.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,positioning}
\begin{document}

\begin{tikzpicture}[node distance=1cm]
\node[circle,minimum width=7cm] (circ) {};
\foreach \X [count=\Y] in {32,25,50,17}
{\node  (cn\Y) at ({-(\Y-2.5)*360/4}:3.5) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 4)]in {1,...,4}
{\draw[-latex,shorten >=4pt,shorten <=4pt] (cn\LastY) to[bend left=10] (cn\Y);}

\begin{scope}[start chain = going below,
every node/.append style={on chain,,xshift=-{cot(76)*1.5cm}},
every join/.style=latex-]
\node[below=of cn4] (n0) {$36$};
\draw[latex-] (cn4) -- (n0);
\node[join] (n6) {$9$};
\node[join] (n5) {$1$};
\node[join] (n4) {$24$};
\node[join] (n3) {$4$};
\node[join] (n2) {$46$};
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};
\end{scope}

\end{tikzpicture}
\end{document}

• If you use [bend left=30] instead of [bend left=10] it looks much better. One can compute the "optimal" bend or draw the arcs differently. Is that what you're asking? – marmot Jan 8 at 18:59
• It's true that [benf left=30] makes it a lot better, but if we take Zarko's solution from the other question, we can see that it is able to draw a circle quite nicely, though the tail doesn't fit in very well. It didn't make it [yet] to change the slope of the tail so that it gets out of the circle. I don't think the 76-degree slope will survive on this case. (Unless you apply your magic again!) – Joep Awinita Jan 8 at 19:15

Sorry for the confusion. I did not think about arbitrary numbers of nodes, but I should. Here is a version that draws the connections on a precise circle. (In Zarko's nice answer there are still parameters that need to be adjusted by hand. Yet it is true that for long arcs arcs tend to look better than bend left.) The disadvantage is that it takes a while to compile.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,positioning,calc,intersections}
\begin{document}

\begin{tikzpicture}[node distance=1cm]
\path[name path=big circle] (0,0) circle (\Radius cm);
\foreach \X [count=\Y] in {32,25,50,17}
{\node[name path global=\Y-circ,inner sep=4pt,circle]  (cn\Y) at
({-(\Y-2.5)*360/4}:\Radius) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 4)]in {1,...,4}
{
\path[name intersections={of=big circle and \LastY-circ,by={aux0,aux2},sort
by=big circle},
name intersections={of=big circle and \Y-circ,by={aux1,aux3},sort
by=big circle}];
\draw[-latex]
let \p1=($(aux0)-(0,0)$),\p2=($(aux3)-(0,0)$),
\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},
\n3={(ifthenelse(\n2<\n1,\n2,\n2-360)} in
}

\begin{scope}[start chain = going below,
every node/.append style={on chain,,xshift=-{cot(76)*1.5cm}},
every join/.style=latex-]
\node[below=of cn4] (n0) {$36$};
\draw[latex-] (cn4) -- (n0);
\node[join] (n6) {$9$};
\node[join] (n5) {$1$};
\node[join] (n4) {$24$};
\node[join] (n3) {$4$};
\node[join] (n2) {$46$};
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};
\end{scope}
\end{tikzpicture}
\end{document}


Alternatively one can find approximate values to be fed into bend left. The following code compiles much faster but not yield exact circles.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,positioning,calc}
\begin{document}

\begin{tikzpicture}[node distance=1cm]
\foreach \X [count=\Y] in {32,25,50,17}
{\node[inner sep=4pt,circle]  (cn\Y) at
({-(\Y-2.5)*360/4}:\Radius) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 4)]in {1,...,4}
{
\path (cn\LastY) -- (cn\Y) coordinate[pos=0](aux0) coordinate[pos=1](aux1);
\draw[-latex]
let \p1=($(aux0)-(0,0)$),\p2=($(aux1)-(0,0)$),
\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},
\n3={0.45*(\n1-ifthenelse(\n2<\n1,\n2,\n2-360)} in
(cn\LastY) to[bend left=\n3] (cn\Y);
}

\begin{scope}[start chain = going below,
every node/.append style={on chain,,xshift=-{cot(76)*1.5cm}},
every join/.style=latex-]
\node[below=of cn4] (n0) {$36$};
\draw[latex-] (cn4) -- (n0);
\node[join] (n6) {$9$};
\node[join] (n5) {$1$};
\node[join] (n4) {$24$};
\node[join] (n3) {$4$};
\node[join] (n2) {$46$};
\node[join] (n1) {$12$};
\node[join] (n0) {$2$};
\end{scope}
\end{tikzpicture}
\end{document}


• The compilation is definitely acceptable. I think your first version is great. However, when I consider another sequence of numbers --- a bit smaller ---, the graph is still nice, but the tail ended up on the right side, making the rho letter show up backwards. – Joep Awinita Jan 8 at 20:26