子图内的数组

子图内的数组

我想知道如何将数组放入子图中(如果可以的话)。我可以毫无问题地将以下代码放入图形语句中,但在子图中却失败了,我不明白为什么。例如,这个编译正常:

\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}

但这无法编译并且出现错误:

\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}

更新,subfig 包也不起作用。

\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}

有任何想法吗?

答案1

不要使用\[...\]$...$在里面\subfloat(我切换到了更可靠的subfig包,但我猜同样适用于过时的包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}

在此处输入图片描述

还要注意,我添加了一些%字符以防止出现虚假的空格。

相关内容