[Tex/LaTex] “\c@subfigure already defined” when using subfig and subcaption

subcaptionsubfigsubfloats

The following is my thesis preamble:

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

I must use subfigure package for

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

But I end up getting errors as follows:

    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.

And some more errors as attached

enter image description here

How can I get rid of these errors?

Best Answer

Just use the subcaption package. Instead of \subfloat[]{} use \subcaptionbox{}{}.

The subcaption documentation is exceptionally good; you should read it. 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}

I also think it doesn't make sense to use both \centering and all of those \hspace{\fill} commands.

Related Question