18

I'd like to place 17 evenly-spaced nodes around a circle. I am very new to Tikz and am following the Petri nets example in the manual. I would like to do something similar — essentially just recreating a better version of this, complete with all the steps described in the Wikipedia article.

Does anyone know how to place the nodes in this way? I'd appreciate and all advice!

3 Answers 3

28

Time to call \foreach.

\documentclass{report}
\usepackage{tikz,calc}

\begin{document}
\begin{tikzpicture}
\foreach \a in {1,2,...,17}{
\draw (\a*360/17: 4cm) node{angle \a};
}
\end{tikzpicture}
\end{document}

enter image description here

6
  • Okay, that works nicely for most of it, however I have a few issues: firstly, will I still be able to connect each "angle a" with arrows? Secondly, all of my nodes are named differently; how might I label them individually? Thanks for this first step though, I hadn't thought of \foreach!
    – AYT
    Nov 16, 2013 at 21:49
  • 1
    @AYT Please don't slowly build-up the question. Your linked picture is not that innocent to be formulated as put 17 nodes around a circle.
    – percusse
    Nov 16, 2013 at 21:50
  • @AYT, use a second variable. But you'll have to describe it one by one until number 17. \foreach \a/\t in {1/one,2/two,<insert here the others>,17/seventeen}. Then you can use \t on the code.
    – Sigur
    Nov 16, 2013 at 21:52
  • @Sigur That's more or less worked, though I'm having some issue with the spacing. Any idea how to fix it? Thanks for all the help so far.
    – AYT
    Nov 16, 2013 at 22:09
  • 3
    @Sigur: You can do the loop even simpler: \foreach \a [count=\c] in {<label1>,<label2>,...,label17>}{\node at (\c*360/17:4) {\a};} Nov 16, 2013 at 23:27
8

With PSTricks' ultimate macro \curvepnodes.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}
\degrees[10]
\begin{document}
\makeatletter
\begin{pspicture}(-3,-3)(3,3)
    \curvepnodes[plotpoints=11]{0}{10}{2.7 t \pst@angleunit PtoC}{A}
    \psnccurve[showpoints](0,9){A}
    \multido{\i=0+1}{10}{\uput[\i](A\i){$A_{\i}$}}
\end{pspicture}
\makeatother
\end{document}

enter image description here

Notes: Herbert or other PSTricks maintainers, please give me an RPN operator angleunit to avoid typing \makeatletter ... \makeatother that consumes more keystrokes.

Animation

How to gradually make a circle with a closed curve of variable points.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node,pst-plot}

\begin{document}
\makeatletter
\multido{\iA=2+1}{20}{%
\def\N{\iA}
\degrees[\N]
\begin{pspicture}(-3,-3)(3,3)
    \curvepnodes[plotpoints=\numexpr\N+1]{0}{\N}{2.7 t \pst@angleunit PtoC}{A}
    \psnccurve(0,\numexpr\N-1){A}
    \multido{\i=0+1}{\N}{\uput[\i](A\i){$A_{\i}$}}
\end{pspicture}}
\makeatother
\end{document}

enter image description here

2

What about graph?

\documentclass{report}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \graph[clockwise, radius=4cm, n=17]
    {
        label1,label2,label3,label4,label5,label6,label7,label8,label9,label10,label11,label12,label13,label14,label15,label16,label17;
    };
\end{tikzpicture}
\end{document}

Adding arcs to it is as easy as writing label1->[bend right]label2;.

I'm quite confident there is a shorter way to set labels, but I don't know about it right now, sorry.

rendered image

5
  • 1
    Welcome! The necklace routing can make the connection between the nodes lie on the circle. Feb 24 at 13:46
  • @Qrrbrbirlbel I came here because I was looking for something similar but much more graph related, that's why I commented on this. Thank you! The only issue I see on necklace routing is that the ring covers the nodes too, as shown on the image on your answer!
    – Foxhole
    Feb 25 at 15:10
  • No, I've added the gray circle to show that the edges lie perfectly on the circle. (See the heading.) It isn't generated by the code or the library. Feb 25 at 17:13
  • Just noticed, sorry
    – Foxhole
    Feb 25 at 21:47
  • No problem, I didn't explain it very good in my answer. Feb 25 at 23:22

You must log in to answer this question.

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