0

I have the following tikz picture in my tex document:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,arrows.meta,shapes.misc}
\usepackage{xifthen}
\begin{document}
\begin{center}
\begin{tikzpicture}[>={Stealth[inset=0pt,length=8pt,angle'=28,round]}]
  \def \n {8}
  \def \radius {2cm}
  \def \margin {8} % margin in angles, depends on the radius
  \def\inittimes{{"1", "8", "3", "2", "6", "5", "7", "4"    }}%
  \tikzset{cross/.style={cross out, draw, 
           minimum size=2*(#1-\pgflinewidth), 
           inner sep=0pt, outer sep=0pt, thick}, cross/.default={6.5}}
  \foreach \s in {1,...,\n}
  {
    \pgfmathsetmacro\l{\inittimes[\s - 1]}
    \ifthenelse{\s = 3}{ \pgfmathsetmacro\fcolor{"lightgray"}}{ \pgfmathsetmacro\fcolor{"white"}}
    \node[draw, circle, fill=\fcolor ] (n\l) at ({360/\n * (\s - 1) + 90 }:\radius) {$\l$} ;
    \ifthenelse{\l = 5 \OR \l = 8}{\draw ({360/\n * (\s - 1) + 90 }:\radius) node[cross] {}}{};
  }
  \foreach \d in {4,...,\n}
  {
    \ifthenelse{\d = 5 \OR \d = 8}{}{
      \pgfmathsetmacro\l{\d + 1]}
      \foreach \k in {\l,...,8} 
      {
        \draw[->] 
          (n\d) edge node[fill=none,draw=none]{\tiny election} (n\k);
      }
    };
  }
\end{tikzpicture}
\end{center}
\end{document}

Which is rendered like this:

enter image description here

The problem is that the incoming arrows at nodes 5 and 7 don't align nicely with center of the nodes, but are off-center.

Is it possible to fine-tune the arriving positions of the arrows, so they look like they point to center?

2
  • 1
    \pgfmathsetmacro gives you a decimal number, try with \pgfmathtruncatemacro instead, which gives an integer. E.g. if \l becomes 7.0, TikZ will interpret .0 as the anchor of the 7 node, so the arrow ends up pointing at the right side of the node. Jan 28, 2018 at 11:44
  • This is fantastic, it worked! Thanks so much @TorbjørnT.
    – user000001
    Jan 28, 2018 at 11:48

0

Browse other questions tagged .