For using a TikZ matrix as part of a nested tikzpicture, I define the former in advance and store it in a savebox.
However, when I add a second column, compilation fails. It seems to be due to the & (see MWE below). The log notably says: ! Package pgf Error: Single ampersand used with wrong catcode.
Question: How to define a TikZ matrix with multiple columns in a savebox?
\documentclass{article}
\usepackage{tikz}
\newsavebox{\testsbox}
\savebox{\testsbox}{
\begin{tikzpicture} [borders/.style={draw, help lines}]
\matrix[borders]{
\node [borders] {11};
% &
% \node [borders] {12};
\\
};
\end{tikzpicture}
}
\begin{document}
This example stops working as soon as you add a second column (i.e. uncomment lines 9 and 10).
\begin{tikzpicture}
\node {\usebox{\testsbox}};
\end{tikzpicture}
\end{document}


\savebox{\testsbox}and\end{tikzpicture}matter and go into the horizontal box\testsbox. โ Heiko Oberdiek Apr 08 '17 at 02:15