# Arrays inside a subfigure

I'd like to know how to put an array inside a subfigure (if it can be done). I have no problem putting the following code inside a figure statement but in subfigure it fails miserably and I cannot figure out why. For example this compiled fine:

\documentclass[]{article}

\usepackage{subfigure}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}                         % Input encoding
\usepackage{listings}               % Code Formatting
\usepackage{amsmath}                                    % Math
\usepackage{tikz}                   % TikZ library for graphs
\usetikzlibrary{calc,arrows}

\newcommand{\tikzmark}[1]{%
\tikz[overlay,remember picture] \node (#1) {};}

%opening
\title{}
\author{}

\begin{document}

\begin{figure}
\centering
$\begin{array}{*{3}{c}} \tikzmark{a} 1 & 2 & 3 \\ \\ 8 & * & 4 \\ \\ 7 & 6 & 5 \tikzmark{b} \\ \end{array}$
\tikz[overlay,remember picture] \draw[-triangle 45] ($(b.south west)+(0.2,-0.1)$) -- ($(a.north east)+(-0.3,0.2)$);
\end{figure}

\end{document}


But this fails to compile without errors:

\documentclass[]{article}

\usepackage{subfigure}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}                         % Input encoding
\usepackage{listings}               % Code Formatting
\usepackage{amsmath}                                    % Math
\usepackage{tikz}                   % TikZ library for graphs
\usetikzlibrary{calc,arrows}

\newcommand{\tikzmark}[1]{%
\tikz[overlay,remember picture] \node (#1) {};}

%opening
\title{}
\author{}

\begin{document}

\begin{figure}
\centering
\subfigure[]{
$\begin{array}{*{3}{c}} \tikzmark{a} 1 & 2 & 3 \\ \\ 8 & * & 4 \\ \\ 7 & 6 & 5 \tikzmark{b} \\ \end{array}$
\tikz[overlay,remember picture] \draw[-triangle 45] ($(b.south west)+(0.2,-0.1)$) -- ($(a.north east)+(-0.3,0.2)$);
}
\end{figure}

\end{document}


Update, subfig package also does not work.

\documentclass[]{article}

\usepackage{subfig}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}                         % Input encoding
\usepackage{listings}               % Code Formatting
\usepackage{amsmath}                                    % Math
\usepackage{tikz}                   % TikZ library for graphs
\usetikzlibrary{calc,arrows}

\newcommand{\tikzmark}[1]{%
\tikz[overlay,remember picture] \node (#1) {};}

%opening
\title{}
\author{}

\begin{document}

\begin{figure}
\centering
\subfloat[]{
$\begin{array}{*{3}{c}} \tikzmark{a} 1 & 2 & 3 \\ \\ 8 & * & 4 \\ \\ 7 & 6 & 5 \tikzmark{b} \\ \end{array}$
\tikz[overlay,remember picture] \draw[-triangle 45] ($(b.south west)+(0.2,-0.1)$) -- ($(a.north east)+(-0.3,0.2)$);
}
\end{figure}

\end{document}


Any ideas?

• I believe that subfugure is deprecated and you should use subfig pacakge instead. – Peter Grill Jan 28 '14 at 21:40
• get rid of the blank line within the array. however, since you end the next-to-last line with \\ , put in some dummy code, perhaps \mbox{} (but if you don't need that blank last line, omit the double backslash from the previous line). – barbara beeton Jan 28 '14 at 21:45
• well you are correct on that, it just a proof of concept; but again I cannot compile it successfully using subfigure, any ideas on that? – jtimz Jan 28 '14 at 21:51

Don't use $...$ but $...$ inside \subfloat (I switched to the more reliable subfig package, but I guess the same will apply to the obsolete subfigure):

\documentclass[]{article}

\usepackage{subfig}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}                         % Input encoding
\usepackage{listings}               % Code Formatting
\usepackage{amsmath}                                    % Math
\usepackage{tikz}                   % TikZ library for graphs
\usetikzlibrary{calc,arrows}

\newcommand{\tikzmark}[1]{%
\tikz[overlay,remember picture] \node (#1) {};}

%opening
\title{}
\author{}

\begin{document}

\begin{figure}
\centering
\subfloat[]{%
$\begin{array}{*{3}{c}} \tikzmark{a} 1 & 2 & 3 \\ \\ 8 & * & 4 \\ \\ 7 & 6 & 5 \tikzmark{b} \\ \end{array}$%
\tikz[overlay,remember picture] \draw[-triangle 45] ($(b.south west)+(0.2,-0.1)$) -- ($(a.north east)+(-0.3,0.2)$);%
}
\end{figure}

\end{document}


Notice also that I added some % characters to prevent spurious blank spaces.

• while we are at it, do you happen to know a way that I can color both the tip and the line of the arrow? – jtimz Jan 28 '14 at 22:25
• @jtimz you can add a color to the options for \draw, as in \draw[red,-triangle 45]... – Gonzalo Medina Jan 28 '14 at 22:28