为什么该子表显示未定义的控制序列

为什么该子表显示未定义的控制序列

当我运行此代码时,出现 \subfloat 标签中未定义控制序列的错误。我该如何解决?

\documentclass[preprint,12pt]{elsarticle}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
%\usepackage{mathtools}
%\usepackage{xspace}
\usepackage{booktabs}
\usepackage{adjustbox}
%\usepackage{subcaption}
\usepackage{subfigure}

\begin{document}

\begin{table}[!ht]
\centering
   \subfloat[First Subtable\label{tab:chapter4:1a}]{
     \tiny
     \centering
     \begin{tabular}{|c|c|c|}\hline
       a&b&c\\
       d&e&f\\\hline
     \end{tabular}
   }
   \subfloat[Second Subtable\label{tab:chapter4:1b}]{
     \tiny
     \centering
     \begin{tabular}{|c|c|c|}\hline
       g&h&i\\
       j&k&l\\\hline
     \end{tabular}
   }
   \subfloat[Third Subtable\label{tab:chapter4:1c}]{
     \tiny
     \centering
     \begin{tabular}{|c|c|c|}\hline
       m&n&o\\
       p&q&r\\\hline
     \end{tabular}
   }
   \caption{Testing}\label{tab:chapter4:1}
\end{table}
\end{document}

答案1

在您的 MWE (最小工作示例) 中,您加载了subfigure已过时且未定义环境的包subfloat。您无需加载它subfig(观察包名称的差异)。您不应该同时加载这两个包!

尝试以下 MWE:


\documentclass[preprint]{elsarticle}
\usepackage{subfig}   % <--- missed package, it is not compatible with "subfigure" !
%\captionsetup[subfloat]{justification=RaggedRight}

\begin{document}
\begin{table}[!ht]
\centering
%\tiny
   \subfloat[First Subtable\label{tab:chapter4:1a}]{
     \begin{tabular}{|c|c|c|}\hline
       a&b&c\\
       d&e&f\\  \hline
     \end{tabular}
   }\hfil
   \subfloat[Second Subtable\label{tab:chapter4:1b}]{
     \begin{tabular}{|c|c|c|}\hline
       g&h&i\\
       j&k&l\\  \hline
     \end{tabular}
   }\hfil
   \subfloat[Third Subtable\label{tab:chapter4:1c}]{
     \begin{tabular}{|c|c|c|}\hline
       m&n&o\\
       p&q&r\\  \hline
     \end{tabular}
   }
   \caption{Testing}\label{tab:chapter4:1}
\end{table}
\end{document}

其运行没有任何错误并且给出:

在此处输入图片描述

相关内容