I have the following code:

\foreach \x in {0,1,2,3,4}

Is there a possibility to accomplish the same thing with something like the following pseudo-code:

\foreach \x in {x1 to x2}
  • 3
    \foreach \x in {x1,...,x2}. You can find more options in the manual.
    – percusse
    Oct 2, 2016 at 11:12

1 Answer 1


As @percusse says in the comment, various options for this are covered in the pgf and tikz manual. Here are a few examples:

  • For the integers from 0 to 10:

    \foreach \x in {0,...,10}
  • For the even integers from 0 to 10:

    \foreach \x in {0,2,...,10}

(The stepping is determined by the difference between the first two numbers provided.)

  • You can change the pattern midway. Thus, to get 0,1,2,3,4,6,8,10,12 write:

    \foreach \x in {0,...,4,6,8,...,12}
  • 1
    Inside a list you need 8 whitespaces for code marking ;)
    – percusse
    Oct 2, 2016 at 22:35

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.