# Captioning tikz matrix with subfigure [duplicate]

I am having trouble wrapping a tikzpicture, which is a matrix of nodes, within a subfigure. I would like this tikzpicture to be captioned and labelled. However I am getting the following error:

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

l.23 }

?


Here is the code that reproduces the issue.

\documentclass[12pt]{book}
\usepackage{subfigure}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{figure}[ht]
\centering
\subfigure[Laplacian $9 \times 9$ filter]{
\begin{tikzpicture}[cell/.style={rectangle,draw=black}]
\matrix[matrix of nodes]{
0& 0& 1& 1& 2& 1& 1& 0& 0\\
0& 1& 3& 5& 5& 5& 3& 1& 0\\
1& 3& 5& 3& 0& 3& 5& 3& 1 \\
1& 5& 3& -12& -23& -12& 3& 5& 1 \\
2& 5& 0& -23& -41& -23& 0& 5& 2 \\
1& 5& 3& -12& -23& -12& 3& 5& 1 \\
1& 3& 5& 3& 0& 3& 5& 3& 1\\
0& 1& 3& 5& 5& 5& 3& 1& 0 \\
0& 0& 1& 1& 2& 1& 1& 0& 0 \\
};
\end{tikzpicture}
\label{fig:log-filter-discret}
}
\hspace{.2in}
\subfigure[LoG representation]{
\includegraphics[width=.45\linewidth]{log-img.png}
\label{fig:log-filter}
}
\caption{discretized LoG and its representation}
\end{figure}
\end{document}

• Welcome to TeX.SX! You can highlight code-blocks, either indent them by four spaces or use the {} on the gui. Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. – Andrew Oct 30 '18 at 7:49
• Out of topic, but subfigure is deprecated – NBur Oct 30 '18 at 8:47
• @NBur The question may serve as an example case of it, in case people like me can not locate this problem. As for deprecation, the discussion there doesn't seem to give a better replacement. – MeadowMuffins Oct 30 '18 at 10:50

Using the ampersand replacement= key, as in Problem with defining shortcuts for TikZ matrices, solves the issue.

\documentclass[12pt]{book}
\usepackage{subfigure}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{figure}[ht]
\centering
\subfigure[Laplacian $9 \times 9$ filter]{
\begin{tikzpicture}[cell/.style={rectangle,draw=black}]
\matrix[ampersand replacement=\&,matrix of nodes]{
0 \& 0 \& 1 \& 1   \& 2  \& 1  \& 1 \& 0 \& 0 \\
0 \& 1 \& 3 \& 5   \& 5  \& 5  \& 3 \& 1 \& 0 \\
1 \& 3 \& 5 \& 3   \& 0  \& 3  \& 5 \& 3 \& 1 \\
1 \& 5 \& 3 \& -12 \& -23\& -12\& 3 \& 5 \& 1 \\
2 \& 5 \& 0 \& -23 \& -41\& -23\& 0 \& 5 \& 2 \\
1 \& 5 \& 3 \& -12 \& -23\& -12\& 3 \& 5 \& 1 \\
1 \& 3 \& 5 \& 3   \& 0  \& 3  \& 5 \& 3 \& 1 \\
0 \& 1 \& 3 \& 5   \& 5  \& 5  \& 3 \& 1 \& 0 \\
0 \& 0 \& 1 \& 1   \& 2  \& 1  \& 1 \& 0 \& 0 \\
};
\end{tikzpicture}
\label{fig:log-filter-discret}
}
\hspace{.2in}
\subfigure[LoG representation]{
%\includegraphics[width=.45\linewidth]{log-img.png}
\includegraphics[width=.45\linewidth]{example-image-a}
\label{fig:log-filter}
}
\caption{discretized LoG and its representation}
\end{figure}
\end{document}


• Thanks a lot. I think wrapping it with subfigure triggered the irregularity of ampersand (without subfigure it works just fine). – MeadowMuffins Oct 30 '18 at 10:46