# How can I make a graph rho-shaped whose nodes are numbers?

I managed to get the two pictures below. I think I'd have to rotate the straight line and connect its end to the number 615 so that it looks like the letter rho (ρ). How can I do that? Feel free to suggest a whole different approach.

Notice how the arrows of the straight line are too small compared to the ones in the cycle. I'd also appreciate seeing an approach where these arrow sizes are similar. It's okay if I have to type up each node — as long defining their position is a sane procedure. I'm sure whatever you come up with will better than I could do today — having read only the first pages of the TikZ manual.

% A simple cycle
% Author : Jerome Tremblay
\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\def \n {11}
\def \margin {8} % margin in angles, depends on the radius

%% \draw[step=.5cm,gray,very thin] (-7,-7) grid (7,7);
%% \draw (0,0) circle (0.1cm);
%% --8<---------------cut here---------------start------------->8---
%% the tail
%% \path
%%  (0,0) node [shape=circle,draw,minimum width=1cm]{$2$}
%%  (1,0) node [shape=circle,draw,minimum width=1cm]{$12$}
%%  (2,0) node [shape=circle,draw,minimum width=1cm]{$152$}
%%  (3,0) node [shape=circle,draw,minimum width=1cm]{$1223$}
%%  (4,0) node [shape=circle,draw,minimum width=1cm]{$1031$}
%%  (5,0) node [shape=circle,draw,minimum width=1cm]{$2916$}
%%  (6,0) node [shape=circle,draw,minimum width=1cm]{$751$}
%%  (7,0) node [shape=circle,draw,minimum width=1cm]{$1149$};

%% --8<---------------cut here---------------end--------------->8---

% the cycle
\def \s {1}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$456$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {2}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$1562$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {3}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$792$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {4}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$1872$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {5}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$2152$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {6}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$25$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {7}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$441$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {8}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$615$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {9}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$2993$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {10}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$2329$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\def \s {11}
\node[draw=none] at ({360/\n * -(\s - 1)}:\radius) {$2031$};
\draw[<-, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);

\end{tikzpicture}

\begin{tikzpicture}[node distance=1.5cm,minimum width=1.2cm]
\node(n0) [draw=none] at (-15,0) {$2$};
\node (n1) [draw=none,right of=n0]{$12$};
\node (n2) [draw=none,right of=n1]{$152$};
\node (n3) [draw=none,right of=n2]{$1223$};
\node (n4) [draw=none,right of=n3]{$1031$};
\node (n5) [draw=none,right of=n4]{$2916$};
\node (n6) [draw=none,right of=n5]{$751$};
\node (n7) [draw=none,right of=n6]{$1149$};
\draw [->] (n0) to (n1);
\draw [->] (n1) to (n2);
\draw [->] (n2) to (n3);
\draw [->] (n3) to (n4);
\draw [->] (n4) to (n5);
\draw [->] (n5) to (n6);
\draw [->] (n6) to (n7);
\end{tikzpicture}

\end{document}


Your circle and straight lines can be coded much shorter, which also allows you to change the positions of the various nodes very easily.

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

\begin{tikzpicture}[node distance=1.5cm]
\node[circle,minimum width=7cm] (circ) {};
\foreach \X [count=\Y] in {456,1562,792,1872,2152,25,441,615,2993,2329,2031}
{\node  (cn\Y) at ({-(\Y-2.5)*360/11}:3.5) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 11)]in {1,...,11}
{\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},
every join/.style=-latex]]
\node[below=of cn8] (n0) {2};
\draw[-latex] (cn8) -- (n0);
\node[join] (n1) {$12$};
\node[join] (n2) {$152$};
\node[join] (n3) {$1223$};
\node[join] (n4) {$1031$};
\node[join] (n5) {$2916$};
\node[join] (n6) {$751$};
\node[join] (n7) {$1149$};
\end{scope}
\end{tikzpicture}
\end{document}


Just for fun: the straight line of a latex \rho has an angle of approximately 76 degrees.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[scale=15]{$\rho$};
\draw[white,thick,double=blue] (-0.5,0.6)  -- (-1.05,-1.6)
node[midway,left=5mm,scale=3,blue]{\pgfmathparse{atan2(0.6+1.6,1.05-0.5)}%
$\pgfmathprintnumber{\pgfmathresult}^\circ$};
\end{tikzpicture}
\end{document}


This raises the question if one can make the chain such that it has this angle. The answer is yes.

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

\begin{tikzpicture}[node distance=1.5cm]
\node[circle,minimum width=7cm] (circ) {};
\foreach \X [count=\Y] in {456,1562,792,1872,2152,25,441,615,2993,2329,2031}
{\node  (cn\Y) at ({-(\Y-2.5)*360/11}:3.5) {$\X$}; }
\foreach \Y [remember=\Y as \LastY (initially 11)]in {1,...,11}
{\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 cn8] (n0) {2};
\draw[-latex] (cn8) -- (n0);
\node[join] (n1) {$12$};
\node[join] (n2) {$152$};
\node[join] (n3) {$1223$};
\node[join] (n4) {$1031$};
\node[join] (n5) {$2916$};
\node[join] (n6) {$751$};
\node[join] (n7) {$1149$};
\end{scope}
\end{tikzpicture}
\end{document}


• this remains me to p not to \rho :-) (you beat me for some minutes :-(, it seem that i hibernate) – Zarko Jan 8 at 16:32
• @Zarko Really? If it was a p, the line should extend further up, I think, and for a q it should be on the other side. So, since this is neither p nor q it must be a \rho. ;-) – marmot Jan 8 at 16:36
• good conclusion, indeed +1. well i imagine that rho is different. i will show my answer (don't laughing to much). – Zarko Jan 8 at 16:39
• @marmot, a solution of excellence! However, it assumes the cycle will have more or less 11 nodes, which doesn't adapt too well for when the cycle is more or less say 4 nodes. See for example this new question which asks for a more general solution. – Joep Awinita Jan 8 at 18:58

this is not really answer (for it i was to late for one minute), just an illustration to @marmot how i imagine \rho "tail" to circle ...

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, positioning}

\begin{document}

\begin{tikzpicture}[
node distance = 4mm and 6mm,
start chain = going below left,
box/.style = {minimum width=5ex, inner xsep=0pt,
on chain, join=by latex-}
]
\def \n {11}
\def \margin {8} % margin in angles, depends on the radius
% the cycle
\foreach \s [count=\i from 0,
count=\j from 1] in {456, 1562, 792, 1872, 2152,
25,  441,  615, 2993, 2329, 2031}
{
\node (s\j)  at (-\i*360/\n:\radius) {$\s$};
}
\node (d1) [box, below left=of s8] {$2$};
\node[box]   {$12$};
\node[box]   {$152$};
\node[box]   {$1223$};
\node[box]   {$1031$};
\node[box]   {$2916$};
\node[box]   {$751$};
\node[box]   {$1149$};
\draw[red,-latex]  (d1) -- (s8);
\end{tikzpicture}

\end{document}


as all can see, difference between codes can be neglected ... slope of line can be adjusted with node distance. for example, i would rather start at node on circle with "441" and make slope more stepped:

node distance = 5mm and -2.5ex,


and star with tail:

\node (d1) [box, below left=of s7] {$2$};


for red arrows i was not sure, if it s desired (so it is red)

• +1 but then my LaTeX compiler has a bug. When I compile \documentclass{article} \begin{document} $\rho$ \end{document} I get a symbol where the line on its left is close to vertical (yet it is not precisely vertical). – marmot Jan 8 at 16:47
• @marmot, you are right, i try replicate rho how i usual wrote (in old times) on blackboard. well, my handwriting is not splendid anyway ;-(. thank you! at least i now lear how to write rho :-) – Zarko Jan 8 at 16:55
• The "correct" angle is 76 degrees, see my answer. ;-) (I hope that you practice on the blackboard until you get precisely 76 degrees. ;-) – marmot Jan 8 at 17:01
• oh, you beat me again, @marmot. i didn't check that meanwhile you edit your answer. sorry ... – Zarko Jan 8 at 17:06
• @JoepAwinita I guess you only need to make sure that the ratio of the node distances is the arctan(76) or arccot(76)` depending on how you take the ratio. – marmot Jan 8 at 20:01