# Why does \resizebox around tikzpicture gives me undefined control sequence }?

As indicated in Scale tikz figure to a percentage of \textwidth I was expecting this to work:

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}
\begin{figure}
\resizebox{0.5\textwidth}{!}{%
\begin{tikzpicture}

\matrix(Person) [matrix of nodes,
matrix/.style={rows={1}{fill=gray}},
label=above:Person,
column 1/.style={nodes={text width=1cm, align=center}},
column 2/.style={nodes={text width=2cm}},
column 3/.style={nodes={text width=2.5cm}},
column 4/.style={nodes={text width=2cm}},
column 5/.style={nodes={text width=2cm, align=center}}
] {
id & name       & address       & birth date & occupation.id \\
1  & Mary Smith & Main street 1 & 1970-04-17 & 1 \\
2  & John Doe   & Highway 2     & 1972-07-24 & 1 \\
3  & Clara Doe  & Highway 2     & 1995-11-11 & 2 \\};
\end{tikzpicture}
}
\end{figure}

\end{document}


However, it gives me:

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options

l.24 }

?


What am I doing wrong?

• It shouldn't give that error; if you remove the blank line before \matrix you get the more informative ! Package pgf Error: Single ampersand used with wrong catcode. Look for ampersand replacement in the manual. – egreg Jul 23 '14 at 14:52
• @egreg I am not able to reproduce that :( – jonalv Jul 23 '14 at 14:57
• @egreg, oh, btw, which manual would that be? Some of the various TeX manuals? – jonalv Jul 23 '14 at 15:00
• @jonalv pgf manual. Section 20.5 of the current version. But I am not able to generate the error message noted by egreg either. – Paul Gessler Jul 23 '14 at 15:05

The problem is caused by the & inside the matrix, which are handled in a non-standard way by tikz and cause problems when used as argument in other commands.

The solution is to replace each & by \& and to put ampersand replacement=\& in matrix options, as in the following code:

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}
\begin{figure}
\resizebox{0.5\textwidth}{!}{%
\begin{tikzpicture}
\matrix(Person) [matrix of nodes, ampersand replacement=\&,
matrix/.style={rows={1}{fill=gray}},
label=above:Person,
column 1/.style={nodes={text width=1cm, align=center}},
column 2/.style={nodes={text width=2cm}},
column 3/.style={nodes={text width=2.5cm}},
column 4/.style={nodes={text width=2cm}},
column 5/.style={nodes={text width=2cm, align=center}}
] {
id \& name       \& address       \& birth date \& occupation.id \\
1  \& Mary Smith \& Main street 1 \& 1970-04-17 \& 1 \\
2  \& John Doe   \& Highway 2     \& 1972-07-24 \& 1 \\
3  \& Clara Doe  \& Highway 2     \& 1995-11-11 \& 2 \\};
\end{tikzpicture}
}
\end{figure}

\end{document}