[Tex/LaTex] Subcaption Package Error

captionssubcaptionsubfloatstemplates

I'm having an issue compiling with the subcaption package. I'm starting to write my thesis, and I originally started a chapter with a separate document. This compiled fine and had the following pre-amble

\documentclass[11pt,a4paper]{article}
\usepackage{fullpage,graphicx,amsmath,verbatim,float,caption,subcaption}
\numberwithin{equation}{section}
\numberwithin{figure}{section}

\begin{document}

I then moved to a template for a thesis, (full template is here http://www.sunilpatel.co.uk/thesis-template/ ) I copied across the chapter I have completed into the chapter1.tex file as specified. I also copied across my \usepackage line to give the following preamble in the thesis document:

%% ----------------------------------------------------------------
%% Thesis.tex -- MAIN FILE (the one that you compile with LaTeX)
%% ---------------------------------------------------------------- 

% Set up the document
\documentclass[a4paper, 11pt, oneside]{Thesis}  % Use the "Thesis" style, based on the            ECS Thesis style by Steve Gunn
\graphicspath{{Figures/}}  % Location of the graphics files (set up for graphics to be     in PDF format)

% Include any extra LaTeX packages required
\usepackage[square, numbers, comma, sort&compress]{natbib}  % Use the "Natbib" style    for the references in the Bibliography
\usepackage{verbatim}  % Needed for the "comment" environment to make LaTeX comments
\usepackage{vector}  % Allows "\bvec{}" and "\buvec{}" for "blackboard" style bold vectors in maths
\usepackage{fullpage,graphicx,amsmath,float,caption,subcaption}
\hypersetup{urlcolor=blue, colorlinks=true}  % Colours hyperlinks in blue, but this can   be distracting if there are many links.

When I compile the Thesis.tex file it now has three errors for each of the figures I'm trying to use

  1. ! Use of \@subfloat doesn't match its definition.
  2. ! Missing number, treated as zero.
  3. ! Illegal unit of measure (pt inserted).

An example of the code for one of my figures is as follows:

\begin{figure}[!h]
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[scale=0.35]{figure1}
        \caption{figure1 caption}
        \label{fig: figure1 }
    \end{subfigure}
    \hspace{20mm}
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[scale=0.35]{figure2}
        \caption{figure2 caption}
        \label{fig: figure2 }
    \end{subfigure}
    \caption{Caption}
\end{figure}

If I remove the subfigure package then the file will compile, but the formatting is all screwed up. I'm guessing there are conflicting packages, but i can't find which one it is.

I'm pretty new to latex and just learning the ropes, so if it something silly then I apologise in advance.

Thanks in advance for any help

John

Best Answer

The class loads subfigure which conflicts with subcaption and has been obsolete for several years.

Remove the call of this package from the template. It should do no harm and will allow you to load and use subcaption.


Also the vmargin package that's used by the class has problems of compatibility with other packages, notably atbegshi; it's probably better two switch to geometry for setting the page parameters. You can find an example of conversion in this answer of mine