Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using tikz to draw a mathematical structure. I have labelled all my nodes in my code and I want to use them as arguments in the \draw command but I keep getting this error "! Missing \endcsname inserted." Below is a minimum working example. Kindly help me with this.

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
Putting node and clipping them to their respective positions
\foreach \x in {2,3,4,...,14}
    \foreach \y in {2,3,4}
    {
        \node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.8mm] (u\x\y) at (\x,\y)  {};
    }
%Drawing arrows
\foreach \x in {3,5,...,11}
    {
    \v = \x + 1;
    \draw[->>] (u\x3) -- (u\v2) ;
    }
\end{tikzpicture}
\end{document}
share|improve this question
    
Where did you find this code: \v = \x + 1; ? –  Sigur May 3 at 14:13
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Heiko Oberdiek May 3 at 14:22
    
Also, was the "Putting node..." supposed to be a comment? Anyway, the fact that the first loop didn't generate any errors indicates that \x and \y are macros (text). Therefore to compute \x+1 you must convert \x from text to a number, add one, then convert back to text again. I tried using \pgfmathparse and \pgfmathresult, but got 4.0 instead of 4. –  John Kormylo May 3 at 14:37
    
BTW, you can place an * between \x and \y. It is a legal name character, but not a legal macro name character. –  John Kormylo May 4 at 14:26

2 Answers 2

up vote 3 down vote accepted

Here's another option without extra variables:

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%Putting node and clipping them to their respective positions
\foreach \x in {2,3,4,...,14}
    \foreach \y in {2,3,4}
    {
        \node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.8mm] (u\x\y) at (\x,\y)  {};
    }
%Drawing arrows
\foreach \x  in {3,5,...,11}
    {
      \draw[->>] (u\x3) -- (u\number\numexpr\x+1\relax2) ;
    }
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%Putting node and clipping them to their respective positions
\foreach \x in {2,3,4,...,14}
    \foreach \y in {2,3,4}
    {
        \node [circle,draw=white,fill=white,inner sep=0pt,minimum size=1.8mm] (u\x\y) at (\x,\y)  {};
    }
%Drawing arrows
\foreach \x in {3,5,...,11}
    {
      \pgfmathparse{\x+1}
      \pgfmathtruncatemacro{\v}{\pgfmathresult}
      \draw[->>] (u\x3) -- (u\v2) ;
    }
\end{tikzpicture}
\end{document}

arrows

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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