TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

I have a for loop in tikz which draws n circles I want to name them A, B, C...etc How do I do that? can I create a char array or something similar and use it within the label {$ $}

also if I do


the labels appear as 1*1 and 1*2 how can I actually multiply to get labels as 1 and 2.

\foreach \x in {1,...,2}
    \foreach \y in {1,...,2}
        \node[regular polygon, regular polygon sides=6, draw, inner sep=\hex cm] (hex\x*\y*4) at 
        (\x*\pi*4.2,\y*\pi*1.6 + 0.8*\pi) {};
        \node[zoneMaster] at (\x*\pi*4.2,\y*\pi*1.6 + 0.8*\pi) {};  
        \node[zoneMaster] [minimum size=0.7cm, fill=Black,text=White] at (\x*\pi*4.2,\y*\pi*1.6 + 0.8*\pi) {$\x*\y$};
share|improve this question
Could you turn your snippet into a minimal working examples? This helps people to answer you. – Claudio Fiandrino Feb 21 '13 at 8:05
For the first part of your question \tikz\foreach\l[count=\x from 0]in{A,...,H}\node[circle,draw]at(\x,0){$\l$}; should show the way. Alternatively you can use \let\pgfforAlpha=\pgffor@Alpha (with the appropriate @ catcode change) and then \tikz\foreach\x in{1,...,8}\node[circle,draw]at(\x-1,0){$\pgfforAlpha{\x}$}; – Mark Wibrow Feb 21 '13 at 15:25
up vote 3 down vote accepted

You could use \pgfmathsetmacro or \pgfmathtruncatemacro to compute real or integer values:

enter image description here


  • The style zoneMaster was not defined so I have defined it to be an empty style.
  • The macro \pi is for the greek letter of the mathematical constant, it is not a numerical value. In pgfmath you use pi for the numerical value.





\foreach \x in {1,...,2}
    \foreach \y in {1,...,2}
        \pgfmathsetmacro{\Y}{\y*pi*1.6 + 0.8*pi}%
        \node[regular polygon, regular polygon sides=6, draw, inner sep=1cm] (hex\Label) at 
        (\X,\Y) {};
        \node[zoneMaster] at (\X,\Y) {};  
        \node[zoneMaster] [minimum size=0.7cm, fill=black,text=white] at (\X,\Y) {$\x*\y$};

share|improve this answer
why does \pgfmathsetmacro{} return float value? can I make it integer? – zcqwevb Feb 21 '13 at 8:13
@user494461: Use \pgfmathtruncatemacro to obtain integer values as I have done in the example for the \Label. – Peter Grill Feb 21 '13 at 8:14

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.