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 its \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)

  • 1
    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

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.

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

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.