# node placement in foreach loop

This code produces two coil windings. If I specify them both explicitely, it works fine. If I wrap it in a foreach loop, they don't connect as they should. I tried varying the line width and the preaction line width. That does not affect the mis-alignment. Can anybody see the problem?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{coil/.style={preaction={draw,line width=1mm,white},thick}}%
\begin{tikzpicture}
\newcommand{\iminusone}{0}
\node[inner sep=0,outer sep=0,anchor=center] (0) at (0,0) {};
\foreach \x in {1,...,2}{%
\pgfmathsetmacro{\iminusone}{\x-1}
\draw[coil] (\iminusone)
node[inner sep=0,outer sep=0,anchor=center] (\x) {};
}
\end{tikzpicture}
\begin{tikzpicture}
\node[inner sep=0,outer sep=0,anchor=center] (0) at (0,0) {};
\draw[coil] (0)
node[inner sep=0,outer sep=0,anchor=center] (1) {};
\draw[coil] (1)

• Use \pgfmathtruncatemacro instead of \pgfmathsetmacro. – Maarten Dhondt Jan 9 '16 at 16:12
• @mauricev \pgfmathtruncatemacro rounds the number, or better, it removes the decimals. That's probably why you had that little misalignment, since Maarten's solution helped you. – Alenanno Jan 9 '16 at 16:58
• The expression (1.0) represents a point on the border of the node (1) such that the line between (1.0) and (1.center) is parallel to x-axis. (Similarly (1.north) and (1.90) usually coincide.) – Symbol 1 Jan 10 '16 at 17:47