0

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?

10
  • 9
    You load subfig and subcaption, both are incompatible with another. Overall, the template you are using is just bad. Have a look at en.wikibooks.org/wiki/LaTeX/Scientific_Reports
    – Johannes_B
    Commented Apr 1, 2019 at 5:43
  • 2
    Off-topic: in your shown screenshot of overleaf I can see the complete url to reach your project :-( I do not know, I did not try, to open it. Please do not show this url, wipe it out in the image or just do not add it in the screenshot ...
    – Mensch
    Commented Apr 1, 2019 at 7:09
  • 4
    This is unrelated to overleaf, that just happens to be where you are running latex. Commented Apr 1, 2019 at 10:45
  • Thank you so much everyone.
    – Mihan
    Commented Apr 1, 2019 at 11:15
  • 1
    Do only use/call packages you know and you need for your document ...
    – Mensch
    Commented Apr 1, 2019 at 18:59

2 Answers 2

4

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.

2
  • Well, I created the comparison in the MWEB, that you can get into with the link, overleaf.com/3391682762fdwvbmrpzhrh and also edit. subcaptionbox did not make things better. Please have a look and tell me or make change
    – Mihan
    Commented Apr 1, 2019 at 19:00
  • You have to remove \usepackage{subfig} and \usepackage{subfigmat}. See @Kurt's answer for an excellent solution.
    – jaspast
    Commented Apr 2, 2019 at 14:21
5

To solve your issue and to get a minimal working example you can delete most of your commands in your preamble.

For me it seems you simply copied parts of other tex files in the internet and/or collegues without knowing what the copied tex code does. That is the badest way to tex ...

General rule: Do only use code you understand. Do only use package you had read the documentation (type texdoc subcaption to get the documentation of package subcaption displayed)!

Now please have a look to the following 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}

The blank line after three example-images generates a new line so you get three sub figures aranged in one line.

The result is:

resulting sub figures

Please see that I used option showframe for package geometry to visualize the typing area and margins. To adjust the margins use geometry (texdoc geometry) and do not use the old fashioned commands like \setlength{\textwidth}{8.276in} etc ...

Please see the correct order of calling packages (in most cases hyperref is called last!) ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .