0
\documentclass{minimal}

\usepackage{tikz}


\begin{document}


\begin{tikzpicture}
    \node[circle,draw=black] (t) at (0,0) {};

    \foreach \i in {0,1,...,359}{
        \node[label={\i:$\circ$}] at (t) {};
    }
\end{tikzpicture}


\end{document}

This gets me:

Compilation Result

I expected that the positions of the labels would be circular around the node. However there is a label in north, south, east, west and then on some square path around the node. Can someone explain this to me, please?

Also I would like to have the possibility to have a circular path around the node for label positioning. Is this possible with the label-option?

enter image description here

Here is my exact problem:

\documentclass[border=5pt,tikz]{standalone}

\begin{document}

\begin{tikzpicture}[state/.style={inner sep=0mm,circle,draw=black,minimum width=2mm}]

    \node[state,label={2:Test}] (A) at (0,0) {\tiny A};
    \node[state] (B) at (5,-1) {\tiny B};
    \node[state] (C) at (4,4) {\tiny C};

    \foreach \from/\to in {A/B,B/C,C/A}{
        \path (\from) edge (\to);
    }

\end{tikzpicture}

\end{document}

Using the label-angle will yield a "jump" when switching from 2 to 3 such that it does not fit in between.

Compilation with 2: Compilation with 2

Compilation with 3: enter image description here

Of course you can manually position such a label such that it fits in between (I am aware of this). But this is quite cumbersome if you have to do this for a bunch of labels. I assumed that this should work directly somehow in the label to have an easier placement.

I then tried adding an extra label node:

\documentclass[border=5pt,tikz]{standalone}

\begin{document}

\begin{tikzpicture}[state/.style={inner sep=0mm,circle,draw=black,minimum width=2mm}]

    \node[state] (A) at (0,0) {\tiny A};
    \node[state] (B) at (5,-1) {\tiny B};
    \node[state] (C) at (4,4) {\tiny C};

    \node[anchor=west] at ([shift=(20:3mm)]A) {Test};

    \foreach \from/\to in {A/B,B/C,C/A}{
        \path (\from) edge (\to);
    }

\end{tikzpicture}


\end{document}

Then it works: extra label node

But then you have to modify the anchor of this node depending on the angle. For instance, if you stick to the anchor and use as angle 180, then you get this without changing the anchor to east: enter image description here

So having a "smooth" positioning of the lables on the circle around the object would be really nice.

3
  • the angles of the label position (seems) are rounded to 5 degree resolution, i.e. labels can be placed on direction 0, 5, 10, ... degree. btw, it is unusual that main nodes have far smaller font size than their labels. what should "test!" designate? size of angle? if this is case, than you approach is wrong. correct/better result you can obtain by use tikz library angles.
    – Zarko
    Commented Aug 3, 2018 at 10:43
  • Thanks @Zarko for your comment. I just simplified my example down to this. Currently my nodes are just empty circles and represent cities. The label is the city name. I added just A,B,C to make it easier to see the corresponding part in the code.
    – Arne
    Commented Aug 3, 2018 at 10:53
  • @Zarko: I would say that this is a circumvention not a solution to my problem.
    – Arne
    Commented Aug 3, 2018 at 11:29

1 Answer 1

2

This is partly due to the automatic anchor of the label, and partly due to its shape.

The first can be solved by adding anchor=\i+180 to the label options, and the second by adding circle.

Here are some examples where I added some help lines:

enter image description here

The left case is the default (had to add circle to the node in the \foreach too). The middle case is when the anchor key is given explicitly. You can clearly see that the rectangular shape is the reason that the labels are not on a circle. The third case is when the shape of the label is also set to circle. The small deviations from the red circle are probably (but correct me if I'm wrong) due to the spacing in the $ $ used for the \circ.

The complete code is:

\documentclass[tikz,margin=2mm]{standalone}

\usepackage{tikz}


\begin{document}


\begin{tikzpicture}
    \node[circle,draw=black] (t1) at (0,0) {};

    \foreach \i in {0,30,...,359}{
        \node[label={[draw,draw opacity=0.25]\i:$\circ$}] at (t1) {};
    }

    \node[circle,draw=black] (t2) at (2,0) {};

    \foreach \i in {0,30,...,359}{
        \node[circle,label={[anchor=\i+180,draw,draw opacity=0.25]\i:$\circ$}] at (t2) {};
    }

    \node[circle,draw=black] (t3) at (4,0) {};

    \foreach \i in {0,30,...,359}{
        \node[circle,label={[anchor=\i+180,circle,draw,draw opacity=0.25]\i:$\circ$}] at (t3) {};
    }

    \draw[red] (t1) circle (0.475);
    \draw[red] (t2) circle (0.475);
    \draw[red] (t3) circle (0.475);
\end{tikzpicture}


\end{document}
0

You must log in to answer this question.

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