2

I have labelled all my nodes in my code and some have decimal numbers in their labels. I want to use these labels as arguments in the \draw command but I keep getting this error

! Missing \endcsname inserted.

Below is a minimum working example.

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%Putting node and clipping them to their respective positions
\foreach \x in {1/2,1,10/3,37/3,15.5}
    \foreach \y in {1,1.25,1.5,3,3.5,,4.5}
    {
        \node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.5mm] (u\x\y) at (\x,\y)  {};
    }
%Drawing arrows
\foreach \y in {1.5,3.5}
    {
        \draw[semithick,->] (u1/2\y) -- (u1\number\numexpr\y-0.5\relax) ;
    }
\end{tikzpicture}
\end{document}
2
  • 2
    A dot in a node name has special meaning. It represents the anchor declaration for example (a.45) or (b.west). Here it is causing trouble. I would strongly recommend not using numbers in node names in that way – percusse May 4 '14 at 12:20
  • Just out of curiosity, why are you drawing invisible nodes instead of using \coordinate? – John Kormylo May 4 '14 at 19:19
3

Just as one should not use x[2.5] in a C program, one should avoid using Tikz names with floating point numbers (converted to text). But one can obtain the desired effect using Tikz arrays (not to be confused with LaTeX arrays).

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%Putting node and clipping them to their respective positions
\def\xval{{1/2,1,10/3,37/3,15.5}}
\def\yval{{1,1.25,1.5,3,3.5,4,4.5}}
\foreach \x in {0,1,2,3,4}
    \foreach \y in {0,1,2,3,4,5,6}
    {
        \node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.5mm] (u\x*\y) at (\xval[\x],\yval[\y])  {};
    }
%Drawing arrows
\foreach \y in {2,4}
    {
        \draw[semithick,->] (u1*\y) -- (u1*\number\numexpr\y-1\relax) ;
    }
\end{tikzpicture}
\end{document}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.