3

I have a tikzpicture with a matrix of math nodes. It by itself compiles fine. If I put it in a figure environment, it still compiles fine. However, if i put it in a subfigure environment, it returns that there is a $ missing. Any ideas?

EDIT (@Werner): Here's something that reproduces the problem:

\documentclass{article}
\usepackage{subfig}% http://ctan.org/pkg/subfig
\usepackage{tikz}% http://ctan.org/pkg/pgf
\usetikzlibrary{matrix}
\begin{document}
\begin{figure}
\subfloat[something]{% <---- \subfloat begin
  \begin{tikzpicture}[every node/.style={anchor=west}]
    \matrix (m) [matrix of math nodes, nodes in empty cells]{
      \quad & 1.\quad (x)(Q\supset Fx) & \\
      & 2.\quad Q\supset Fx & \textrm{I,\textbf{UI}} & \\
      & 3.\quad Q \\
      & 4.\quad Fx & 2, 3, \textrm{ M.P.}\\
      & 5.\quad (x)Fx & 4, \textrm{ \textbf{UG}} \\
      & 6.\quad Q\supset(x)Fx & 3-5, \textrm{ C.P.} \\
      & 7.\quad \parbox[t]{2.9cm}{%
        $(x)(Q\supset(x)Fx)\supset$\\
        $[Q\supset(x)Fx]$} & 1-6, \textrm{ C.P.}\\};
    \draw[-stealth] (m-7-2.north east)
                 -| (m-1-1.west) |- (m-1-2);
    \draw[-stealth] (m-6-2.north east)
                 -| (m-3-1.east) |- (m-3-2);
  \end{tikzpicture}%
}% <---- \subfloat end
\caption{This is a caption}
\end{figure}
\end{document}
David Carlisle
  • 757,742
user1536
  • 473

2 Answers2

2

If you add the following to the preamble

\newcommand{\Supset}{\ensuremath{\supset}}%

and use Supset instead of supset, this error changes to

Package pgfbasematrix Error: Single ampersand used with wrong catcode.

See Problem with defining shortcuts for TikZ matrices for more info on this issue.

So, to fix this, you could either use \pgfmatrixnextcell instead &, or ampersand replacement=\& option to \matrix (and then use \& instead of just &) which yields the desired result:

enter image description here

\documentclass{article}
\usepackage{subfig}% http://ctan.org/pkg/subfig
\usepackage{tikz}% http://ctan.org/pkg/pgf
\usetikzlibrary{matrix}

\begin{document}
\newcommand{\Supset}{\ensuremath{\supset}}%
\begin{figure}
\subfloat[something]{% <---- \subfloat begin
  \begin{tikzpicture}[every node/.style={anchor=west}]
    \matrix (m) [matrix of math nodes, nodes in empty cells,ampersand replacement=\&]{
      \quad 
      \& 1.\quad (x)(Q\Supset Fx) \& \\
      \& 2.\quad Q\Supset Fx \& \textrm{I,\textbf{UI}} \& \\
      \& 3.\quad Q \\
      \& 4.\quad Fx \& 2, 3, \textrm{ M.P.}\\
      \& 5.\quad (x)Fx \& 4, \textrm{ \textbf{UG}} \\
      \& 6.\quad Q\Supset(x)Fx \& 3-5, \textrm{ C.P.} \\
      \& 7.\quad \mbox{\parbox[t]{2.9cm}{%
        $(x)(Q\Supset(x)Fx)\Supset$\\
        $[Q\Supset(x)Fx]$}} \& 1-6, \textrm{ C.P.}\\
};
    \draw[-stealth] (m-7-2.north east)
                 -| (m-1-1.west) |- (m-1-2);
    \draw[-stealth] (m-6-2.north east)
                 -| (m-3-1.east) |- (m-3-2);
  \end{tikzpicture}%
}% <---- \subfloat end
\caption{This is a caption}
\end{figure}
\end{document}
Moriambar
  • 11,466
Peter Grill
  • 223,288
  • With the inclusion of ampersand replacement=\&, you don't need to use \Supset; you can revert back to the original \supset. Regardless, this (using a math matrix) seems like something that is basic in its functionality and avoids excessive use of math mode switches using $, yet requires a & -> \& work-around. Is this the only way? – Werner Sep 28 '11 at 20:25
  • Yep, it is possible to revert back but to just supset, but don't see the harm in just using Supset. It just feels "wrong" to use a math symbol like that without a $..$ surrounding it, even though it appears that the symbols and text are in proper math font. Don't know if there are other workarounds, and I certainly would not want to use \pgfmatrixnextcell, but perhaps one of the TikZ experts here will elaborate. – Peter Grill Sep 28 '11 at 20:42
1

Another option is to consider the subcaption package. This post has some good comparisons: subcaption vs. subfig: Best package for referencing a subfigure

Below is an implementation using the subcaption package, and I didn't need to change your TikZ code at all :)

\documentclass{article}
\usepackage{tikz}% http://ctan.org/pkg/pgf
\usetikzlibrary{matrix}
\usepackage{subcaption}

\begin{document}
\begin{figure}
 \centering
 \begin{subfigure}{0.5\textwidth}
  \begin{tikzpicture}[every node/.style={anchor=west}]
    \matrix (m) [matrix of math nodes, nodes in empty cells]{
      \quad & 1.\quad (x)(Q\supset Fx) & \\
      & 2.\quad Q\supset Fx & \textrm{I,\textbf{UI}} & \\
      & 3.\quad Q \\
      & 4.\quad Fx & 2, 3, \textrm{ M.P.}\\
      & 5.\quad (x)Fx & 4, \textrm{ \textbf{UG}} \\
      & 6.\quad Q\supset(x)Fx & 3-5, \textrm{ C.P.} \\
      & 7.\quad \parbox[t]{2.9cm}{%
        $(x)(Q\supset(x)Fx)\supset$\\
        $[Q\supset(x)Fx]$} & 1-6, \textrm{ C.P.}\\};
    \draw[-stealth] (m-7-2.north east)
                 -| (m-1-1.west) |- (m-1-2);
    \draw[-stealth] (m-6-2.north east)
                 -| (m-3-1.east) |- (m-3-2);
  \end{tikzpicture}%
  \caption{Subcaption goes here}
 \end{subfigure}
\caption{This is a caption}
\end{figure}
\end{document}

enter image description here

cmhughes
  • 100,947