2

I want to draw a circle using TIKZ and instead of manually placing the nodes and connecting the nodes I wanted to use loops as any sane person would. Now when I wrote these, the incoming edge seems to be going to some point slightly of the node instead of to its core.

In the example, I included a version with the path manually written out. I am losing my sanity here :D Anyone got any idea as to what is happening here? Any style critique is also very welcome!

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
    \usetikzlibrary{automata}
                
\begin{document}
\begin{tikzpicture}[nodes=state]
\def \number {8}
\def \radius {2cm}
\def \degree {360/\number}

\foreach \s in {1,...,\number}
{
    \node at ({\degree * (\s -1)}:\radius) (\s) {$u_\s$};
}

\foreach \s in {1,...,\number}
{
    \pgfmathsetmacro\result{Mod( (\s), \number)+1}
    \path (\s) edge[bend right = 15] (\result);
}
\end{tikzpicture}

\begin{tikzpicture}[nodes=state]
\def \number {8}
\def \radius {2cm}
\def \degree {360/\number}

\foreach \s in {1,...,\number}
{
    \node at ({\degree * (\s -1)}:\radius) (\s) {$u_\s$};
}

          \path (1) edge[bend right = 15] (2)
%                   edge (5)
                (2) edge[bend right = 15] (3)
%                   edge (6)
                (3) edge[bend right = 15] (4)
%                   edge (7)
                (4) edge[bend right = 15] (5)
%                   edge (8)
                (5) edge[bend right = 15] (6)
                (6) edge[bend right = 15] (7)
                (7) edge[bend right = 15] (8)
                (8) edge[bend right = 15] (1)
                    ;
\end{tikzpicture}
\end{document}
1
  • You need \pgfmathtruncatemacro\result{Mod( (\s), \number)+1} to drop .0 at the end of the number. \foreach \s [evaluate=\s as \result using {int(Mod( (\s), \number)+1)}]in {1,...,\number} { \path (\s) edge[bend right = 15] (\result); } also works.
    – user229669
    Dec 1, 2020 at 17:07

2 Answers 2

2

You need

\pgfmathtruncatemacro\result{Mod( (\s), \number)+1} 

to drop .0, which gets interpreted as a node anchor (the east anchor). Or use evaluate with int.

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata}
                
\begin{document}
\begin{tikzpicture}[nodes=state]
\def \number {8}
\def \radius {2cm}
\def \degree {360/\number}

\foreach \s in {1,...,\number}
{
    \node at ({\degree * (\s -1)}:\radius) (\s) {$u_\s$};
}

\foreach \s [evaluate=\s as \result using {int(Mod( (\s), \number)+1)}]in {1,...,\number}
{
    \path (\s) edge[bend right = 15] (\result);
}
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    BTW, if you are interested in exact circular arcs without overpainting stuff with white, look at e.g. tex.stackexchange.com/a/512539.
    – user229669
    Dec 1, 2020 at 17:39
  • Thanks, I knew it was something stupid like this, just not what :) Could you elaborate on why you use evaluate over macros? I find the syntax rather ugly/unintuitive.
    – Tenaka
    Dec 2, 2020 at 0:27
1

If if the problem is just to arrange the circles on the circle, this can be done relative simple:

\documentclass[tikz, margin=10pt]{standalone}

\begin{document}
    \begin{tikzpicture}[
C/.style = {circle, draw, fill=white, minimum size=7mm, 
            inner sep=0pt, outer sep=0pt}
                        ]
\def \number {8}
\def \radius {2cm}
\def \degree {360/\number}
% circle
\draw   (0,0)   circle[radius=\radius];
% nodes on circle
    \foreach \i [count=\j from 0] in {1,...,\number}
\node (n\i) [C] at (\j*\degree:\radius) {$u_\i$};
    \end{tikzpicture}
\end{document}

enter image description here

Or do I miss/misunderstood something?

4
  • This does not answer the question and overpaints things white, which can backfire terribly.
    – user229669
    Dec 1, 2020 at 17:40
  • I will wait on OP comment. So far in question I didn't find requirement that nodes (circles) had to be transparent.
    – Zarko
    Dec 1, 2020 at 18:05
  • I mainly wanted to find out where this goes wrong. Painting circles and stuff is fine, I prefer real edges as those are extendable. And this is not a one of thing I had to do, but more me learning how to do it correctly for the future, or well, asking others :D Thanks though.
    – Tenaka
    Dec 2, 2020 at 0:23
  • @Tenaka, thanks for comment. Apparently my answer is not what you looking for. Anyway, you should made your question more clear about this (that you not interested for simple solution which require white fill), but solutions proposed by TikZling (who is renomated expert for this :-) )
    – Zarko
    Dec 2, 2020 at 0:47

You must log in to answer this question.

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