13

I want to write a macro that uses TikZ to create a photo like this:

example
(source: msdn.com) .

But, finally I came up with something like this:

TikZ Picture

As you see, the problem is that the arrows go to the wrong side of the end circle (they always go to the right side). Here is the source code of my example:

\documentclass[11pt]{scrartcl}
\usepackage[utf8]{inputenc}  
\usepackage{tikz}
\usetikzlibrary{calc} 
\makeatletter 
\@namedef{color@1}{red!40}
\@namedef{color@2}{green!40}   
\@namedef{color@3}{blue!40} 
\@namedef{color@4}{cyan!40}  
\@namedef{color@5}{magenta!40} 
\@namedef{color@6}{yellow!40}    

\newcommand{\graphitemize}[1]{%
\begin{tikzpicture}[every node/.style={align=center}]  

\foreach \gritem [count=\xi] in {#1}  {\global\let\maxgritem\xi}  

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathtruncatemacro{\angle}{360/\maxgritem*\xi}
\edef\col{\@nameuse{color@\xi}}
\node[circle,
     ultra thick,
     draw=white,
     fill opacity=.5,
     fill=\col,
     minimum size=3cm] (satellite\xi) at (\angle:4cm) {\gritem };
}%

\foreach \gritem [count=\xi] in {#1}
{% 
\pgfmathsetmacro{\xj}{mod(\xi, \maxgritem) + 1}
\edef\col{\@nameuse{color@\xi}}
\draw[<-,line width=.5cm,opacity=.5,\col] (satellite\xj) to[bend left] (satellite\xi);
}%
\end{tikzpicture}  
}%

\begin{document}

\graphitemize{Phase 1,Phase 2, Phase 3, Phase 4}

\end{document} 

Note that I adapted the code from Altermundus answer to this question. How can I fix the end position of the arrows?

5
  • 2
    You should wrap your \draw command for the arrows in \begin{scope}[opacity=.5,transparency group] ... \end{scope} to make sure that the arrow lines and arrow tips have the same colour. Also, note that fill opacity=0.5 also makes the text semitransparent in your nodes, so you should set text opacity=1 after fill opacity. Lastly, if there are no objects behind the graph, you might as well just choose lighter colours, instead of using transparency.
    – Jake
    Apr 23, 2012 at 8:20
  • 1
    Indeed, instead of opacity=.5,\col you can use \col\relax!0.5.
    – percusse
    Apr 23, 2012 at 8:21
  • 2
    I don't know if we have a canonical "What are legal TikZ node names" or not, but maybe we should! In the meantime, here's a similar situation: tex.stackexchange.com/a/28242/86 Apr 23, 2012 at 8:29
  • @AndrewStacey I read percusse's answer after your comment :( Apr 23, 2012 at 8:59
  • 2
    Does this answer your question? Pointing to a node with calculated name, why do I get to the east, not to the center? {p/s while this question is older, I think the other question has a more descriptive title, thus I vote to close in that direction)
    – user202729
    Feb 5, 2023 at 5:04

1 Answer 1

14

The problem comes from the math operation mod(\xi, \maxgritem) + 1. TikZ is giving the result with a number with decimal point such as 1.0, 2.0 etc. and later since you use it in the node naming it becomes satellite1.0,satellite2.0. Coincidentally, this means that the arrow shoud go to the node border at zero angle, hence the weird right side tracking.

You can fix it easily by replacing the operation line with

\pgfmathtruncatemacro{\xj}{mod(\xi, \maxgritem) + 1)} 

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