使用 subfig 和 subcaption 时出现“\c@subfigure 已经定义”

使用 subfig 和 subcaption 时出现“\c@subfigure 已经定义”

以下是我的论文序言:

\documentclass[12pt,english]{article}
\usepackage{subfig}
\usepackage{graphicx} % for graphics
\usepackage{subfigmat}
%\usepackage[draft]{graphicx} % temporarily turn off graphicx
%\usepackage{subfig}
%\setcounter{lofdepth}{2}
%\usepackage{parskip}
\usepackage{caption}  % Enable figure captions or figure notes
\usepackage{subcaption} %Further enable sub captions
\usepackage{booktabs} %for table
\usepackage{amsmath} %for equations and mathematical symbols
\usepackage{amssymb} 
\usepackage{rotating} %for table rotation
\usepackage{lscape}
\usepackage{float} % allow tables to self adjust
\usepackage{morefloats}
\usepackage[flushleft]{threeparttable}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{hyperref} % allow hyper referencing
\usepackage{breakcites}
\usepackage{csquotes}
\usepackage{enumerate} % to get all that enumeration offers
\captionsetup{font=footnotesize}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[round]{natbib} % for bibliography
%\bibliographystyle{cambridgeauthordate}
\usepackage{apalike}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\usepackage[natbibapa]{apacite} % load "apacite" with option "natbibapa" 
%\bibliographystyle{apacite} % specify the bibliography style

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%{plainnat} % regular bibliography
\usepackage[usenames, dvipsnames]{color} % coloring fonts
%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{multirow}
\usepackage{esint}
\usepackage[toc,page]{appendix}
\renewcommand{\cite}{\citeyear}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}
\newtheorem{assumption}{Assumption}
\newtheorem{definition}{Definition}
\newtheorem{proposition}{Proposition}
\makeatletter
\providecommand{\tabularnewline}{\\}
\usepackage{psfrag}\usepackage{multirow}\@ifundefined{definecolor}{\usepackage{color}}{}
\usepackage{colortbl}\usepackage{float}\usepackage{bm}\usepackage[metapost]{mfpic}
% Tree-saver - if turn this on you lose page numbers
 \setlength{\textwidth}{8.276in}
 \setlength{\textheight}{11.405in}
 % Allow 1 in margin on each side and nothing else
 \addtolength{\textwidth}{-2in}
 \addtolength{\textheight}{-2in}
 \setlength{\oddsidemargin}{0pt}
 \setlength{\evensidemargin}{\oddsidemargin}
 \setlength{\topmargin}{0pt}
 \addtolength{\topmargin}{-\headheight}
 \addtolength{\topmargin}{-\headsep}
 \newcommand{\ds}{\displaystyle}
 \newcommand{\bs}{\boldsymbol}
  %\pagenumbering{roman}
 \parindent=0pt
 \parskip=5pt
 \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
 \def\@biblabel#1{}
 \def\ph#1{\phantom{#1}}
 \renewcommand{\baselinestretch}{1.0}

 \title{}
\author{}

\usepackage{babel}

\date{\today}
%\usepackage{calc} % To reset the counter in the document after title page

\makeatother

\begin{document}

\maketitle
\begin{abstract}

我必须使用subfigure

\begin{figure}[!ht]
\setlength{\lineskip}{1ex}% increase spacing
\centering
\subfloat[1998:1]{\includegraphics[width=.3\textwidth]{A1}}%
\hspace{\fill}
\subfloat[1998:2]{\includegraphics[width=.3\textwidth]{A2}}%
\hspace{\fill}
\subfloat[1999:1]{\includegraphics[width=.3\textwidth]{A3}}%
\hspace{\fill}
\subfloat[1999:2]{\includegraphics[width=.3\textwidth]{A4}}%
\hspace{\fill}
\subfloat[2000:1]{\includegraphics[width=.3\textwidth]{A5}}%
\hspace{\fill}
\subfloat[2000:2]{\includegraphics[width=.3\textwidth]{A6}}%
\hspace{\fill}
\subfloat[2001:1]{\includegraphics[width=.3\textwidth]{A7}}%
\hspace{\fill}
\subfloat[2001:2]{\includegraphics[width=.3\textwidth]{A8}}
\hspace{\fill}
\subfloat[2002:1][![enter image description here][1]][1]{\includegraphics[width=.3\textwidth]{A9}}
\hspace{\fill}
\subfloat[2002:2]{\includegraphics[width=.3\textwidth]{A10}}
\hspace{\fill}
\subfloat[2003:1]{\includegraphics[width=.3\textwidth]{A11}}
\hspace{\fill}
\subfloat[2003:2]{\includegraphics[width=.3\textwidth]{A12}}
\caption{\label{figure12} Dynamic crisis transmission maps from 1998-2003}
\end{figure}

但我最终收到如下错误:

    LaTeX Error: Command \c@subfigure already defined.

Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.113 \newcounter{subfigure}
                            [figure]
Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

附件中还有一些错误

在此处输入图片描述

我怎样才能消除这些错误?

答案1

只需使用 subcaption 包即可。而不是\subfloat[]{}使用\subcaptionbox{}{}

子标题文档非常好;您应该阅读它。https://ctan.org/pkg/subcaption?lang=en

\begin{figure}[!ht]
...
\subcaptionbox{1998:1}{\includegraphics[width=.3\textwidth]{A1}} \\
\subcaptionbox{1998:2}{\includegraphics[width=.3\textwidth]{A2}} \\
...
\caption{\label{figure12} Dynamic crisis transmission maps from 1998-2003}
\end{figure}

我还认为同时使用这两个命令\centering以及所有这些\hspace{\fill}命令是没有意义的。

答案2

为了解决您的问题并获得最小的工作示例,您可以删除序言中的大部分命令。

对我来说,你似乎只是复制了互联网和/或同事中其他 tex 文件的部分内容不知道复制的 tex 代码会做什么。这是最糟糕的 tex 方式...

一般规则:只使用您理解的代码。只使用包已经阅读过文档(输入texdoc subcaption以获取显示的包的文档subcaption)!

现在请看一下以下 mwe:

\documentclass[12pt,english]{article}

\usepackage[T1]{fontenc}
\usepackage{babel}

\usepackage[showframe]{geometry} % <====================================

\usepackage[usenames,table,dvipsnames]{xcolor}
\usepackage{graphicx} % for graphics
\usepackage{caption}  % Enable figure captions or figure notes
\usepackage{subcaption} %Further enable sub captions <==================
\captionsetup{font=footnotesize}

\usepackage{hyperref} % allow hyper referencing

\title{Title}
\author{Author}
\date{\today}


\begin{document}

\maketitle
\begin{abstract}
abstract
\end{abstract}

\begin{figure}[!ht]
%\setlength{\lineskip}{1ex}% increase spacing
  \centering
  \subcaptionbox{1998:1}{\includegraphics[width=.3\textwidth]{example-image-a}} 
  \subcaptionbox{1998:2}{\includegraphics[width=.3\textwidth]{example-image-b}} 
  \subcaptionbox{1999:1}{\includegraphics[width=.3\textwidth]{example-image-c}} 

  \subcaptionbox{1999:2}{\includegraphics[width=.3\textwidth]{example-image-a}} 
  \subcaptionbox{2000:1}{\includegraphics[width=.3\textwidth]{example-image-b}} 
  \subcaptionbox{2000:2}{\includegraphics[width=.3\textwidth]{example-image-c}} 

  \subcaptionbox{2001:1}{\includegraphics[width=.3\textwidth]{example-image-a}} 
  \subcaptionbox{2001:2}{\includegraphics[width=.3\textwidth]{example-image-b}} 
  \subcaptionbox{2002:1}{\includegraphics[width=.3\textwidth]{example-image-c}} 

  \subcaptionbox{2002:2}{\includegraphics[width=.3\textwidth]{example-image-a}} 
  \subcaptionbox{2003:1}{\includegraphics[width=.3\textwidth]{example-image-b}} 
  \subcaptionbox{2003:2}{\includegraphics[width=.3\textwidth]{example-image-c}} 

\caption{\label{figure12} Dynamic crisis transmission maps from 1998-2003}
\end{figure}
\end{document}

三个示例图像后的空白行会生成一个新行,因此您可以获得排列在一行中的三个子图。

结果是:

产生的子图

请注意,我使用了showframe包选项geometry来可视化打字区域和页边距。要调整页边距,请使用geometrytexdoc geometry),不要使用诸如等老式命令\setlength{\textwidth}{8.276in}...

请查看调用包的正确顺序(大多数情况下hyperref是最后调用!)...

相关内容