[texhax] dynamically generating tikz node names

Neal H. Walfield neal at walfield.org
Thu Aug 16 23:17:44 CEST 2012

I'm trying to programmatically name a bunch of tikz nodes (actually
pgfplots).  Here is a minimal example:

  \def\alltraces{aaa, bbb, ccc, ddd}
    \node (t\i) at (0, 0) {};
    \foreach \trace in \alltraces {%
      \node[anchor=north] (t\i) at (t\prev.south) {\i \trace};

pgfmathresult returns numbers like 2.0 rather than 2 (\show\i returns,
e.g., \i=macro: ->1.0.), which I think confuses tikz.  Here's an error

  ! Package pgf Error: No shape named t1 is known.
  See the pgf package documentation for explanation.
  Type  H <return>  for immediate help.
  l.21 \plotall

How can I get rid of the .0?  Is this actually the problem?  I don't
think I'm having the non-expandability problem that some people have,
e.g., [1], because my name macros (\i and \prev) are really expanding
to numbers and not token sequences...

  [1] http://tex.stackexchange.com/questions/27769/is-it-possible-to-use-a-macro-to-name-a-tikz-node,

Is there perhaps a better way to dynamically name tikz nodes?



More information about the texhax mailing list