# Including a matrix of math nodes in a TikZ figure in a minipage in a landscape in an afterpage

I want to include a TikZ figure, containing a matrix of math nodes, displayed in landscape mode on its own page in my thesis, in such a way that the nominally surrounding text, which is in fact on the preceding page, is uninterrupted by the incorporation of my figure.

Here is a parody of what I've been doing.

\documentclass[11pt,oneside,british]{book}
\usepackage{amssymb,amsfonts,amsthm,mathtools,afterpage,rotating,pdflscape,tikz}
\usetikzlibrary{matrix,fit,backgrounds,arrows,calc}
\begin{document}
DOGS

\afterpage{%
\clearpage%
\thispagestyle{empty}%
\begin{landscape}%
\begin{figure}[h]%
\caption{A charming tripartite diagram}%
\label{fig:fig}%
\centering
\begin{minipage}[t]{.50\textwidth}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (-0.5,-0.5) grid (0.5,0.5);
\end{tikzpicture}
\end{minipage}%
\begin{minipage}[t]{.45\textwidth}
\begin{tikzpicture}
\draw[step=0.5cm,color=gray] (-0.5,-0.5) grid (0.5,0.5);
\end{tikzpicture}
\end{minipage}%
\begin{minipage}[t]{.05\textwidth}
\begin{tikzpicture}
\tikzstyle{every node}=[font=\scriptsize]
\matrix (m)
[matrix anchor=orgn.center,
ampersand replacement=\&,
matrix of math nodes,
column sep={0.5cm,between origins},
row sep={.5cm,between origins},
inner sep=0cm]
at (-0.25,-0.3)
{
0 & 1\\
\node(orgn) {E_\infty};& 0\\
};
\draw[step=0.5cm,color=gray] (-0.5,-0.5) grid (0.5,0.5);
\draw[line width=0.4mm]
(-0.5,0) -- (0.5,0)
(0,-0.5) -- (0,0.5);
;
\end{tikzpicture}
\end{minipage}
\end{figure}
\end{landscape}
\clearpage
}

HATS
\end{document}


The error engendered is thus: Undefined control sequence. <argument> \pgf@matrix@last@nextcell@options.

The code works if I don't include the matrix of math nodes—which, however, I need. The ampersand replacement is included because it's been suggested in seemingly related situations online, but it doesn't seem to help me to include it.

I should also note that this originally occurred in a chapter I had \input into a larger document, and when I do that, I get distinct errors, regarding math mode, ampersands, and carriage returns:

I don't know if the same problems are causing both these errors, but wasn't sure how to provide a minimal example for the compound document.

How do I make it work?

• If you say ampersand replacement=\&, you must use \& and not just & as a column separator in your matrix. After correcting the problem your code compiles for me. Is this the problem? – Ignasi Mar 31 '15 at 6:57

If ampersand replacement=\& is used in a \matrix style, \& must be used as column separator inside \matrix declaration.

\matrix (m) [matrix anchor=orgn.center,
ampersand replacement=\&,
matrix of math nodes,
column sep={0.5cm,between origins},
row sep={.5cm,between origins},
inner sep=0cm]
at (-0.25,-0.3)
{
0 \& 1\\   %<---------------- & replaced by \&
|(orgn)| E_\infty \& 0\\  %<---------------- & replaced by \&
};


Side comment: all nodes from a matrix of nodes are named with matrix_name-row-column, but if an special name must be assigned to any node, syntax |(name)| does it. In OP's code \node (orgn) {E_\infty} can be replaced by |(orgn)| E_\infty.