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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone explain what does [count=\i] in a foreach mean?

Antal S-Z's answer to Fitting a list of points with TikZ and it's \foreach use this. It is also mentioned in Increment loop variable in inner foreach loop, but I am not able to locate documentation on this in the TikZ-PGF manual (V2.10)

share|improve this question
The TikZ manual has a nice index, which is quite useful for finding where an option is described. – Caramdir Jun 25 '11 at 10:14
up vote 27 down vote accepted

Section Options to customize the foreach-statement. (pages 507-508):

/pgf/foreach/count= <macro>from<value> (no default) This key allows <macro> to hold the position in the list of the current item. The optional from<value> statement allows the counting to begin from <value>.

So, for example, in

\foreach \x [count=\xi] in {a,...,e}

the \x will take the values a,b,c,d,e, while \xi will take the values 1,2,3,4,5, and in

\foreach \x [count=\xi from 3] in {a,...,e}

the \x will still take the values a,b,c,d,e, while \xi will now take the values 3,4,5,6,7.

share|improve this answer
Since which version of Tikz is this function available? – user8442 Oct 8 '11 at 10:01

Your Answer


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.