Is it possible to access an array and use one of its elements to specify the last iteration point in a TikZ \foreach?
I've tried with the code below but I keep getting a compilation error:
! Argument of \pgffor@@dotscharcheck has an extra }.
<inserted text>
\par
l.49 }
And here's a minimal example:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\begin{document}
\begingroup
\newdimen\bitSize
\bitSize=2mm
\newdimen\bitSep
\bitSep=0.5mm
\newdimen\bitBigSep
\bitBigSep=3mm
\begin{tikzpicture}[%
auto,
every node/.style={%
node distance=0pt,
},
bit/.style={%
draw,
rectangle,
minimum size=\bitSize,
inner sep=0pt,
node distance=\bitSep,
},
]
\def\numBits{{4, 8, 4}}
\foreach \i in {1, 2, 3} {%
\pgfmathtruncatemacro\prevI{\i-1}
\foreach \j in {1, ..., \numBits[\prevI]} {%
\pgfmathtruncatemacro\prevJ{\j-1}
% Draw bit
\ifnum \j=1
\ifnum \i=1
\node [bit] (bit\i-\j) {};
\else
\node [bit, right=\bitBigSep of bit\prevI-\numBitsArray[\prevI-1]]
(bit\i-\j) {};
\fi
\else
\node [bit, right=of bit\i-\prevJ] (bit\i-\j) {};
\fi
}
}
\end{tikzpicture}
\endgroup
\end{document}
pgfmanual (v.3.10) page 578, an example is given similar to what you have, implicitly, given.\foreach \x [remember=\x as \lastx (initially A)] in {B,...,H}{$\overrightarrow{\lastx\x}$, }. It remembers the previous iteration argument as\lastx. It would be much easier if you can provide an example showing what the goal is in your nested iteration. – percusse Sep 30 '11 at 11:49rememberwill help me here, but I actually managed to solve it with inspiration from this question: http://tex.stackexchange.com/questions/12091/tikz-foreach-loop-with-macro-defined-list – gablin Sep 30 '11 at 12:002.10. Sorry. And would you care posting your working solution here? – percusse Sep 30 '11 at 12:02...with something that would compile e.g.\node at (\n,\j) {\n,\j};such that one can execute the code and can obtain something, doesn't matter what. Sorry again :) – percusse Sep 30 '11 at 12:07