Subfigures with captions for thesis using \subfigure package
The subfigure
package provides a \subfigure
command, not an environment.
The syntax is
\subfigure[<optional argument>]{mandatory argument}
what happens with your code is that the mandatory argument is \centering
. Chaos ensues.
\documentclass[a4paper, 11pt, oneside]{report}
\usepackage[square, numbers, comma, sort&compress]{natbib}
\usepackage{amsmath,graphicx,amssymb,braket,xcolor,subfigure,upgreek,bbold}
\usepackage{esint}
\begin{document}
\begin{figure}
\centering
\subfigure[Fig.\ A]{\includegraphics[width=3cm]{example-image}\label{fig:Ex_Im}}
\subfigure[Fig.\ B]{\includegraphics[width=6cm]{example-image}\label{fig:Ex_Im2}}
\caption{This is the caption.}\label{fig:Label}
\end{figure}
\end{document}
However, subfigure
is obsolete and you should prefer either subfig
or subcaption
.
With the former package, the syntax is
\documentclass[a4paper, 11pt, oneside]{report}
\usepackage[square, numbers, comma, sort&compress]{natbib}
\usepackage{amsmath,graphicx,amssymb,braket,xcolor,subfig,upgreek,bbold}
\usepackage{esint}
\begin{document}
\begin{figure}
\centering
\subfloat[Fig.\ A]{\includegraphics[width=3cm]{example-image}\label{fig:Ex_Im}}\quad
\subfloat[Fig.\ B]{\includegraphics[width=6cm]{example-image}\label{fig:Ex_Im2}}
\caption{This is the caption.}\label{fig:Label}
\end{figure}
\end{document}
With the latter, you can use \subcaptionbox
:
\documentclass[a4paper, 11pt, oneside]{report}
\usepackage[square, numbers, comma, sort&compress]{natbib}
\usepackage{amsmath,graphicx,amssymb,braket,xcolor,subcaption,upgreek,bbold}
\usepackage{esint}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{Fig.\ A\label{fig:Ex_Im}}{\includegraphics[width=3cm]{example-image}}\quad
\subcaptionbox{Fig.\ B\label{fig:Ex_Im2}}{\includegraphics[width=6cm]{example-image}}
\caption{This is the caption.}\label{fig:Label}
\end{figure}
\end{document}
I'd prefer subcaption
, but the class you're using might not like it; in this case, go with subfig
.
Related videos on Youtube
Kio
Updated on December 08, 2020Comments
-
Kio almost 3 years
I want to put two figures side by side with their sub captions for my thesis. The template has the package \subfigure included, thus I cannot use for example \subcaption. If I use the following code:
\documentclass[a4paper, 11pt, oneside]{article} \usepackage[square, numbers, comma, sort&compress]{natbib} \usepackage{amsmath,graphicx,amssymb,braket,xcolor,subfigure,upgreek,bbold} \usepackage{esint} \begin{document} \begin{figure} \centering \begin{subfigure}[Fig.A] \centering \includegraphics[width=3cm]{Ex_Im.pdf} \label{fig:Ex_Im} \end{subfigure} \begin{subfigure}[Fig.B] \centering \includegraphics[width=6cm]{Ex_Im2.pdf} \label{fig:Ex_Im2} \end{subfigure} \caption{This is the caption.}\label{fig:Label} \end{figure} \end{document}
I get the following figure:
If, on the contrary I use:
\begin{figure} \centering \begin{subfigure}[Fig.A] \centering \includegraphics[width=3cm]{Ex_Im.pdf} \label{fig:Ex_Im} \caption{This is the caption A.} \end{subfigure} \begin{subfigure}[Fig.B] \centering \includegraphics[width=6cm]{Ex_Im2.pdf} \label{fig:Ex_Im2} \caption{This is the caption B.} \end{subfigure} \caption{This is the caption.}\label{fig:Label} \end{figure}
Then I get this:
So as you can there is no good result with either of those examples.
Thanks in advance for your help.
This is the cls file:
%%Thesis.cls \NeedsTeXFormat{LaTeX2e}[1996/12/01] \ProvidesClass{Thesis} [2007/22/02 v1.0 LaTeX document class] \def\baseclass{book} \DeclareOption*{\PassOptionsToClass{\CurrentOption}{\baseclass}} \def\@checkoptions#1#2{ \edef\@curroptions{\@ptionlist{\@currname.\@currext}} \@tempswafalse \@tfor\@this:=#2\do{ \@expandtwoargs\in@{,\@this,}{,\@curroptions,} \ifin@ \@tempswatrue \@break@tfor \fi} \let\@this\@empty \if@tempswa \else \PassOptionsToClass{#1}{\baseclass}\fi } \@checkoptions{11pt}{{10pt}{11pt}{12pt}} \PassOptionsToClass{a4paper}{\baseclass} \ProcessOptions\relax \LoadClass{\baseclass} \newcommand\bhrule{\typeout{------------------------------------------------------------------------------}} \newcommand\Declaration[1]{ \btypeout{Declaration of Authorship} %\addtotoc{Declaration of Authorship} \thispagestyle{plain} \null\vfil %\vskip 60\p@ %\begin{center}{\huge\bf Declaration of Authorship\par}\end{center} %\vskip 60\p@ {\normalsize #1} \vfil\vfil\null %\cleardoublepage } \newcommand\btypeout[1]{\bhrule\typeout{\space #1}\bhrule} \def\today{\ifcase\month\or January\or February\or March\or April\or May\or June\or July\or August\or September\or October\or November\or December\fi \space \number\year} \usepackage{setspace} \onehalfspacing \setlength{\parindent}{0pt} \setlength{\parskip}{2.0ex plus0.5ex minus0.2ex} \usepackage{vmargin} \setmarginsrb { 1.5in} % left margin { 0.6in} % top margin { 1.0in} % right margin { 0.8in} % bottom margin { 20pt} % head height {0.25in} % head sep { 9pt} % foot height { 0.3in} % foot sep \raggedbottom \setlength{\topskip}{1\topskip \@plus 5\p@} \doublehyphendemerits=10000 % No consecutive line hyphens. \brokenpenalty=10000 % No broken words across columns/pages. \widowpenalty=9999 % Almost no widows at bottom of page. \clubpenalty=9999 % Almost no orphans at top of page. \interfootnotelinepenalty=9999 % Almost never break footnotes. \usepackage{fancyhdr} \lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}} \rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage} \chead{}\lfoot{}\rfoot{}\cfoot{} \pagestyle{fancy} \renewcommand{\chaptermark}[1]{\btypeout{\thechapter\space #1}\markboth{\@chapapp\ \thechapter\ #1}{\@chapapp\ \thechapter\ #1}} \renewcommand{\sectionmark}[1]{} \renewcommand{\subsectionmark}[1]{} \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else \hbox{} \thispagestyle{empty} \newpage \if@twocolumn\hbox{}\newpage\fi\fi\fi} \usepackage{amsmath,amsfonts,amssymb,amscd,amsthm,xspace} \theoremstyle{plain} \newtheorem{example}{Example}[chapter] \newtheorem{theorem}{Theorem}[chapter] \newtheorem{corollary}[theorem]{Corollary} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{proposition}[theorem]{Proposition} \newtheorem{axiom}[theorem]{Axiom} \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition} \theoremstyle{remark} \newtheorem{remark}[theorem]{Remark} \usepackage[normal,small,sc]{caption} \setlength{\captionmargin}{20pt} \newcommand{\fref}[1]{Figure~\ref{#1}} \newcommand{\tref}[1]{Table~\ref{#1}} \newcommand{\eref}[1]{Equation~\ref{#1}} \newcommand{\cref}[1]{Chapter~\ref{#1}} \newcommand{\sref}[1]{Section~\ref{#1}} \newcommand{\aref}[1]{Appendix~\ref{#1}} \renewcommand{\topfraction}{0.85} \renewcommand{\bottomfraction}{.85} \renewcommand{\textfraction}{0.1} \renewcommand{\dbltopfraction}{.85} \renewcommand{\floatpagefraction}{0.75} \renewcommand{\dblfloatpagefraction}{.75} \setcounter{topnumber}{9} \setcounter{bottomnumber}{9} \setcounter{totalnumber}{20} \setcounter{dbltopnumber}{9} \usepackage{graphicx} \usepackage{epstopdf} %\usepackage[scriptsize]{subfigure} \usepackage{booktabs} \usepackage{rotating} \usepackage{listings} \usepackage{lstpatch} \lstset{captionpos=b, frame=tb, basicstyle=\scriptsize\ttfamily, showstringspaces=false, keepspaces=true} \lstdefinestyle{matlab} { language=Matlab, keywordstyle=\color{blue}, commentstyle=\color[rgb]{0.13,0.55,0.13}\em, stringstyle=\color[rgb]{0.7,0,0} } \usepackage[pdfpagemode={UseOutlines},bookmarks=true,bookmarksopen=true, bookmarksopenlevel=0,bookmarksnumbered=true,hypertexnames=false, colorlinks,linkcolor={blue},citecolor={blue},urlcolor={red}, pdfstartview={FitV},unicode,breaklinks=true]{hyperref} \pdfstringdefDisableCommands{ \let\\\space } \newcommand*{\supervisor}[1]{\def\supname{#1}} \newcommand*{\examiner}[1]{\def\examname{#1}} \newcommand*{\degree}[1]{\def\degreename{#1}} \newcommand*{\authors}[1]{\def\authornames{#1}} \newcommand*{\addresses}[1]{\def\addressnames{#1}} \newcommand*{\university}[1]{\def\univname{#1}} \newcommand*{\UNIVERSITY}[1]{\def\UNIVNAME{#1}} \newcommand*{\department}[1]{\def\deptname{#1}} \newcommand*{\DEPARTMENT}[1]{\def\DEPTNAME{#1}} \newcommand*{\group}[1]{\def\groupname{#1}} \newcommand*{\GROUP}[1]{\def\GROUPNAME{#1}} \newcommand*{\faculty}[1]{\def\facname{#1}} \newcommand*{\FACULTY}[1]{\def\FACNAME{#1}} \newcommand*{\subject}[1]{\def\subjectname{#1}} \newcommand*{\keywords}[1]{\def\keywordnames{#1}} \supervisor {} \examiner {} \degree {} \authors {} \university {\texorpdfstring{\href{University Web Site URL Here (include http://)} {University Name}} {University Name}} \UNIVERSITY {\texorpdfstring{\href{University Web Site URL Here (include http://)} {} {UNIVERSITY NAME (IN BLOCK CAPITALS)}} \department {\texorpdfstring{\href{Department or School Web Site URL Here (include http://)} {}} {Department or School Name}} \DEPARTMENT {\texorpdfstring{\href{Department or School Web Site URL Here (include http://)} {DEPARTMENT OR SCHOOL NAME (IN BLOCK CAPITALS)}} {DEPARTMENT OR SCHOOL NAME (IN BLOCK CAPITALS)}} \group {\texorpdfstring{\href{Research Group Web Site URL Here (include http://)} {Research Group Name}} {Research Group Name}} \GROUP {\texorpdfstring{\href{Research Group Web Site URL Here (include http://)} {RESEARCH GROUP NAME (IN BLOCK CAPITALS)}} {RESEARCH GROUP NAME (IN BLOCK CAPITALS)}} \faculty {\texorpdfstring{\href{Faculty Web Site URL Here (include http://)} {Faculty Name}} {Faculty Name}} \FACULTY {\texorpdfstring{\href{Faculty Web Site URL Here (include http://)} {FACULTY NAME (IN BLOCK CAPITALS)}} {FACULTY NAME (IN BLOCK CAPITALS)}} \addresses {} \subject {} \keywords {} \renewcommand\maketitle{ \btypeout{Title Page} \hypersetup{pdftitle={\@title}} \hypersetup{pdfsubject=\subjectname} \hypersetup{pdfauthor=\authornames} \hypersetup{pdfkeywords=\keywordnames} \thispagestyle{empty} \begin{titlepage} \let\footnotesize\small \let\footnoterule\relax \let \footnote \thanks \setcounter{footnote}{0} \null\vfil \vskip 60\p@ \begin{center} \setlength{\parskip}{0pt} %{\large\textbf{\UNIVNAME}\par} %\vfill {\huge \bf \@title \par} \vfill %{\LARGE by \par} %\smallskip {\large \textbf{\authornames} \par} \vfill {\large A thesis submitted for the degree of\par} {\large \textbf{Doctor of Philosophy} \par} \bigskip \bigskip %{\large in the \par} %{\large \facname \par} {\large \textbf{\deptname} \par} {\large\textbf{\UNIVNAME}\par} \bigskip \bigskip {\large \textbf{\authornames} \par} \vfill \includegraphics[scale=0.1]{} \bigskip \bigskip \bigskip \ \ {\large \@date \par} \bigskip \end{center} \par \@thanks \vfil\null \end{titlepage} \setcounter{footnote}{0}% \global\let\thanks\relax \global\let\maketitle\relax \global\let\@thanks\@empty \global\let\@author\@empty \global\let\@date\@empty \global\let\@title\@empty \global\let\title\relax \global\let\author\relax \global\let\date\relax \global\let\and\relax \cleardoublepage } \newenvironment{abstract} { \btypeout{Abstract Page} \thispagestyle{empty} {\huge \textbf{Abstract} \par} \bigskip } { \vfil\vfil\vfil\null \cleardoublepage } \addtocounter{secnumdepth}{1} \setcounter{tocdepth}{6} \newcounter{dummy} \newcommand\addtotoc[1]{ \refstepcounter{dummy} \addcontentsline{toc}{chapter}{#1}} \renewcommand\tableofcontents{ \btypeout{Table of Contents} \begin{spacing}{1}{ \setlength{\parskip}{1pt} \if@twocolumn \@restonecoltrue\onecolumn \else \@restonecolfalse \fi \chapter*{\contentsname \@mkboth{ \MakeUppercase\contentsname}{\MakeUppercase\contentsname}} \@starttoc{toc} \if@restonecol\twocolumn\fi \cleardoublepage }\end{spacing} } \renewcommand\listoffigures{ \btypeout{List of Figures} %\addtotoc{List of Figures} \begin{spacing}{1}{ \setlength{\parskip}{1pt} \if@twocolumn \@restonecoltrue\onecolumn \else \@restonecolfalse \fi \chapter*{\listfigurename \@mkboth{\MakeUppercase\listfigurename} {\MakeUppercase\listfigurename}} \@starttoc{lof} \if@restonecol\twocolumn\fi \cleardoublepage }\end{spacing} } \renewcommand\listoftables{ \btypeout{List of Tables} %\addtotoc{List of Tables} \begin{spacing}{1}{ \setlength{\parskip}{1pt} \if@twocolumn \@restonecoltrue\onecolumn \else \@restonecolfalse \fi \chapter*{\listtablename \@mkboth{ \MakeUppercase\listtablename}{\MakeUppercase\listtablename}} \@starttoc{lot} \if@restonecol\twocolumn\fi \cleardoublepage }\end{spacing} } \newcommand\listsymbolname{Abbreviations} \usepackage{longtable} \newcommand\listofsymbols[2]{ \btypeout{\listsymbolname} \addtotoc{\listsymbolname} \chapter*{\listsymbolname \@mkboth{ \MakeUppercase\listsymbolname}{\MakeUppercase\listsymbolname}} \begin{longtable}[c]{#1}#2\end{longtable}\par \cleardoublepage } \newcommand\listconstants{Physical Constants} \usepackage{longtable} \newcommand\listofconstants[2]{ \btypeout{\listconstants} \addtotoc{\listconstants} \chapter*{\listconstants \@mkboth{ \MakeUppercase\listconstants}{\MakeUppercase\listconstants}} \begin{longtable}[c]{#1}#2\end{longtable}\par \cleardoublepage } \newcommand\listnomenclature{Symbols} \usepackage{longtable} \newcommand\listofnomenclature[2]{ \btypeout{\listnomenclature} \addtotoc{\listnomenclature} \chapter*{\listnomenclature \@mkboth{ \MakeUppercase\listnomenclature}{\MakeUppercase\listnomenclature}} \begin{longtable}[c]{#1}#2\end{longtable}\par \cleardoublepage } \newcommand\acknowledgements[1]{ \btypeout{Acknowledgements} %\addtotoc{Acknowledgements} \thispagestyle{plain} {\huge{\textbf{Acknowledgements}} \par} \bigskip {\normalsize #1} \vfil\vfil\null } \newcommand\dedicatory[1]{ \btypeout{Dedicatory} \thispagestyle{plain} \null\vfil \vskip 60\p@ \begin{center}{\Large \sl #1}\end{center} \vfil\null \cleardoublepage } \renewcommand\backmatter{ \if@openright \cleardoublepage \else \clearpage \fi \addtotoc{\bibname} \btypeout{\bibname} \@mainmatterfalse} \endinput %% %% End of file `Thesis.cls'.
-
Kio almost 4 yearsDone. Regarding the \subfigure, even if I don't include it in the \usepackage it tells me it is still there.
-
egreg almost 4 yearsThe syntax is completely wrong: with the
subfigure
package, there is a\subfigure
command, not asubfigure
environment.
-
-
Kio almost 4 yearsAwesome! Thank you so much!
-
Kio almost 4 yearsOne small thing though. My (a) and (b) appear as (A) and (B). Any idea why that might occur?
-
egreg almost 4 years@Kio No, if you don't point to a place where the
Thesis
class can be examined. -
Kio almost 4 yearsBut I need to use this Thesis template...
-
egreg almost 4 years@Kio Sure, but if I can't see it, there's nothing I can say about the labels.
-
Kio almost 4 yearsCould it be something I can change in the cls file?
-
egreg almost 4 years@Kio Last time I ask: can you make the document class available? Without knowing its internals it's impossible to help. There are literally hundreds of
Thesis
classes around. -
Kio almost 4 yearsI have added it now.
-
egreg almost 4 years@Kio As far as I can see, your class already loads
subfigure
, so you have to resort to the first code I wrote (with the\subfigure
command). I get (a) and (b) (lowercase). -
Kio almost 4 yearsIf I do that the figures appears on top of each other and not subcaption. I commented the \subfigure in the cls file and then I can use \subcaption, but (a) and (b) appear in capital letters then.