I have a list of lists, and I'm using nested \foreach loops to iterate through them. By using [count=\var], I'm able to use \var to access the length of the outer loop (after I've iterated through). However, I am not able to use this method to access the length of the inner loops. In my case, all the inner loops should have the same length, but technically I wanted to access the length of the last of the inner loops. Here's what I have so far:
\documentclass{article}
\usepackage{tikz}
\begin{document}
% The first two work:
\begin{tikzpicture}
\foreach \from [count=\to] in {2,3,1} {
\draw (\from,1) -- (\to,2);
}
\draw[gray] (0.5,0.5) rectangle (\to+0.5,2.5);
\end{tikzpicture}
\begin{tikzpicture}
\foreach \from [count=\to] in {1,3,2} {
\draw (\from,1) -- (\to,2);
}
\draw[gray] (0.5,0.5) rectangle (\to+0.5,2.5);
\end{tikzpicture}
% This one does not work:
\begin{tikzpicture}
\foreach \list [count=\row] in {{2,3,1},{1,3,2}} {
\foreach \from [count=\to] in \list {
\draw (\from,\row) -- (\to,\row+1);
}
}
\draw[gray] (0.5,0.5) rectangle (\to+0.5,\row+1.5);
\end{tikzpicture}
\end{document}
Here's what I want to end up with:


\newcommand*{\LastLoopValue}{0}, 2. in second for loop \xdef\LastLoopValue{\to} and finaly 3.\draw[gray] (0.5,0.5) rectangle (0.5+\LastLoopValue,\row+1.5);instead of\draw[gray] (0.5,0.5) rectangle (\to+0.5,\row+1.5);– Bobyandbob Jul 13 '17 at 19:56