3

I need this to work with any \n I decide to set in TikZ (because the diagram at this point is undetermined). I don't mind setting margin manually, but no arcs except the one from node 3 to 4 connect correctly, and I'm clearly not good at working with polar coordinates.

This is a modified version of http://www.texample.net/tikz/examples/cycle/, except I would like for it to start on the left, and it needs to be clockwise.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{center}
\begin{tikzpicture}[scale=0.7]

\def \n {5}
\def \radius {3cm}
\def \margin {8.2} % margin in angles, depends on the radius
% https://tex.stackexchange.com/questions/47172/what-does-the-colon-in-tikz-coordinates-mean
% http://www.texample.net/tikz/examples/cycle/

\foreach \s in {1,...,\n}
{
\node[draw, circle] at ({180 - 360/\n * (\s - 1)}:\radius) {$\s$};
\draw[->, >=latex] ({180 - 360/\n * (\s - 1)-\margin}:\radius) 
% https://tex.stackexchange.com/questions/175016/how-is-arc-defined-in-tikz
  arc ({2*\margin}:{-(180/\n)  + 2* \margin }:(\radius * 1.5);
}
\end{tikzpicture}
\end{center}


\end{document}

Output:

enter image description here

0

3 Answers 3

6
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\def \n {5}
\def \radius {3cm}
\def \margin {8} % margin in angles, depends on the radius
\foreach \s in {1,...,\n} {
  \node[draw, circle] at ({360/\n*(1-\s)}:-\radius) {\s};
  \draw[-latex] ({360/\n*(1-\s)-\margin}:-\radius) 
    arc ({360/\n*(1-\s)-\margin}:{-360/\n*\s+\margin}:-\radius);
}
\end{tikzpicture}
\end{document}

enter image description here

5

As pointed out here, this is a tree, and such trees understand clockwise.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{trees}
\begin{document}
\begin{tikzpicture}[circ/.style={circle,draw},
level 1/.style={sibling angle=72,level distance=pi*1cm},
edge from parent/.style= {draw=none}]
\coordinate (Center)  [clockwise from=270]
    child foreach \X in {1,...,5} { node[circ] (\X) {\X}};
\foreach \X [remember=\X as \LastX (initially 5)] in  {1,...,5}
{\draw[-latex] (\LastX) to[bend left=28] (\X);}   
\end{tikzpicture}
\end{document}

enter image description here

4

Following the example you linked, you can change the degree at which nodes are drawn and the direction of the arrowhead in \draw:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}

\def \n {5}
\def \radius {3cm}
\def \margin {8} % margin in angles, depends on the radius

\foreach \s in {1,...,\n}
{
  \node[draw, circle] at ({360/\n * (\n - \s - 1)}:\radius) {$\s$};
  \draw[<-, =>latex] ({360/\n * (\s - 1)+\margin}:\radius) 
    arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\end{tikzpicture}

enter image description here

6
  • 2
    It is 1 -> 2 -> 3 -> 4 -> 5 -> 1, not 1 -> 5... It is not that easy
    – user156344
    Commented May 18, 2019 at 18:41
  • 1
    Just replace \draw[<-, >=latex]... by \draw[-latex] ...?
    – user121799
    Commented May 18, 2019 at 18:45
  • @marmot, thanks for the tip!
    – jGaboardi
    Commented May 18, 2019 at 18:48
  • 1
    This solution does not start the first node at the left, and does not have clockwise arcs. Commented May 18, 2019 at 18:58
  • 1
    Oh, I just see. It is okay now - downvote retracted
    – user156344
    Commented May 19, 2019 at 6:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .