Hi all,
Well, finally here is a syntax that does compile:
Code: Select all
\usetikzlibrary{shapes.arrows,chains,positioning}
\begin{tikzpicture}[font=\tt]
% NOTE: matrix generates '! Missing } inserted.' for:
% * ANY line-ends inside - make sure to comment empty lines!
% * if it is completely empty (i.e. doesn't have any nodes)
\matrix[draw=red]
{
% the individual nodes work:
%% \node[right] {AA} ; \\
%% \node[right] {BB} ; \\
% this foreach passes - but line ends are not interpreted; so nodes overlap!
\foreach \nn in {AA,BB}
\node[right] {\nn} ; \\
};
\end{tikzpicture}
.. and as the comment says - the code compiles, nodes are rendered - however, the line ending (\\) is not interpreted, and so the nodes overlap.. Apparently, using the curly braces {} to encapsulate the \foreach argument was the problem...
So, it is possible syntactically to use \foreach in a tikz \matrix with nodes (apart from the line break problem)...
I thought also that it may have had to do with using the 'variable' \nn, as I found in the pgf manual:
Each assignment in a let operation starts with \p, usually followed by a <digit>: \x digit , \y digit , \p digit ...
Instead of writing \p1 = ..., we write \n2 = .... Here, “n” stands for “number” (while “p” stands for “point”).
... but apparently, that is not the problem here ...
Cheers!
EDIT Feb 28 2011: I think I found something close to an answer:
TikZ \foreach loop with macro-defined list - TeX - LaTeX - Stack Exchange
The \mymacro isn't expanded by the \foreach loop, but only afterwards. You need to remove the braces { } around the macro to make it work:
...
Note that while normally both arguments {\mymacro} and \mymacro are identical, \foreach seems to test for { and expands the argument if it isn't present.
...
As far as I remember this is an explicit feature of the \foreach macro.
...
Btw. the pgf manual says: Still in the easiest case, <list> is either a comma-separated list of values surrounded by curly braces or it is the name of a macro that contain such a list of values.