3

As you can see in the pic the lines from the top balls do not start as expected from the south, but from the east. Below the arrows from the XOR perfectly fit to my expectation. What do I have to change?

Thanks in advance

enter image description here

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{shadows}

\begin{document}
  \begin{tikzpicture}[%
    bit/.style={circle,shading=ball,minimum width=1cm,ball color=white,path fading=fade inside},
    bit2/.style={circle,shading=ball,minimum width=1cm,ball color=blue,path fading=fade inside},
    ]

    \tikzfading[name=fade inside,inner color=transparent!80,outer color=transparent!30] 

        \foreach \n in {0,...,4,20,21,22,23,24}{%
            % x
                \pgfmathparse{mod(\n,5)}
                \edef\myx{\pgfmathresult}
            % y
                \pgfmathparse{int(\n/5)}
                \pgfmathparse{int(5-\pgfmathresult)}
                \edef\myy{\pgfmathresult}

            \node [bit] (\n) at (\myx,\myy) {};
        }

        \foreach \n in {20,21,22,23,24}{%
            \pgfmathparse{\n-20}
            \edef\myk{\pgfmathresult}

            \node [above of=\n, inner sep=0] (plus\n) {$\bigoplus$};
            \draw [-stealth] (plus\n) -- (\n);
            \draw [-stealth] (\myk) -- (plus\n);
        }

  \end{tikzpicture}
\end{document}
4
  • 2
    Probably not easy to search for, but I'm quite sure the same thing has been asked before. \pgfmathparse creates a float, so you get e.g. 1.0, and the .0 is seen as an anchor. Use \pgfmathtruncatemacro{\myk}{\n-20}, or \pgfmathparse{int(\n-20)}, which gives you an integer. Jul 20, 2018 at 6:17
  • 2
    tex.stackexchange.com/questions/161532/… looks like more or less a clear duplicate, if you agree I can close. Jul 20, 2018 at 6:24
  • Ok, \pgfmathtruncatemacro{\myk}{\n-20} solved the problem. You may close, duplicate. Jul 20, 2018 at 7:16
  • 1
    Huh? If you change \pgfmathparse{\n-20}\edef\myk{\pgfmathresult} to \pgfmathtruncatemacro{\myk}{\n-20}, it works as expected. And the anchor is never reported in an error like that, if you use \draw (sdiof.north); the error says "no shape sdiof known". Jul 20, 2018 at 7:16

0

Browse other questions tagged .