19

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!

AYT
  • 343

3 Answers3

29

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

Sigur
  • 37,330
  • 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 '13 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 '13 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 '13 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 '13 at 22:09
  • Since you need nodes with different widths I recommend to look for another method. You can split the nodes in blocks and insert using different radius. – Sigur Nov 16 '13 at 22:45
  • 3
    @Sigur: You can do the loop even simpler: \foreach \a [count=\c] in {<label1>,<label2>,...,label17>}{\node at (\c*360/17:4) {\a};} – Tom Bombadil Nov 16 '13 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

Foxhole
  • 121