4

I am trying to draw put some number along (i,i-1) where i varies from 1 to 10. I have tried to implement this idea using foreach command. But the following code can not be compiled by LaTeX. Do you have any idea to make the following code work or other solutions to do the same function?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}
\begin{tikzpicture}

  \foreach \i/\j in {1/2,2/3,.../...,9/10}{
    \node at (\i cm,\j cm) {(\i,\j)};
  };

\end{tikzpicture}
\end{document}

note that the foreach command.

  • In your text j=i-1 but in your code j=i+1. I've used i+1 in my code but, of course, it can be easily modified. – CarLaTeX Jul 21 '17 at 4:28
7

I think it's better to let tikz calculate the j as i+1:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}
\begin{tikzpicture}
    \foreach[evaluate=\i as \j using int(\i+1)] \i in {1,2,...,9}{%
    \node at (\i cm,\j cm) {(\i,\j)};
    }
\end{tikzpicture}
\end{document}

enter image description here

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.