[Tex/LaTex] Subcaption environment failed. All figures containing a subfigure crashing all of a sudden

floatsgraphicssubcaptionsubfloats

I am currently writing my thesis in LaTeX. Today, all of a sudden, LaTeX started crashing. All the figures which contain a subfigure (NOTE: I am using the subcaption package) started receiving the following error:

Illegal unit of measure (pt inserted). \begin{subfigure}[b]{0.4\textwidth}

Also receiving other errors such as:

Missing number, treated as zero. \begin{subfigure}[b]{0.4\textwidth}

and

\begin{figure} on input line 170 ended by \end{subfigure}. \end{subfigure}

Below is an example of the code I'm using to generate subfigures.

\begin{figure}[htbp!]  % h t b p ! H for positioning of floats
\begin{subfigure}[b]{0.5\textwidth}
    \includegraphics[width=\textwidth]{CRMBuffetPSD5deg00eta0600}
    \caption{$\alpha$ = 5.0 \dg}
    \label{subfig:CRMBuffetPSD5deg00}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}
    \includegraphics[width=\textwidth]{CRMBuffetPSD6deg00eta0600}
    \caption{$\alpha$ = 6.0 \dg}
    \label{subfig:CRMBuffetPSD6deg00}
\end{subfigure}
\begin{center}
\begin{subfigure}[b]{0.5\textwidth}
    \includegraphics[width=\textwidth]{CRMBuffetPSD6deg50eta0600}
    \caption{$\alpha$ = 6.5 \dg}
    \label{subfig:CRMBuffetPSD6deg50}
\end{subfigure}
\end{center}
\caption{Surface $C_{P}$ response at $\eta$ = 0.6, and various incidences}
\label{fig:CRMBuffetUnsteadyPSD}

\end{figure}

The code worked fine for a significant period of time, today whilst writing I started getting this error. Closing and reopening LaTeX does not fix the issue.

I looked online already and it seems that the only solution found so far was to use the subcaption environment which I already do. Any other tips that could help me start troubleshooting this?

Thanks.

EDIT: I am using the Cambridge PhD thesis template.
EDIT: Error disappears when not using the thesis template anymore. This is undesirable though

Best Answer

The only way to produce these error messages I'm aware of is using the subfigure package as well, and ignoring the first error message. Example:

\documentclass{article}
\usepackage[demo]{graphics}

\usepackage{subfigure}
\usepackage{subcaption}

\begin{document}

\begin{figure}[htbp!]  % h t b p ! H for positioning of floats
\begin{subfigure}[b]{0.5\textwidth}
    \includegraphics[width=\textwidth]{CRMBuffetPSD5deg00eta0600}
    \caption{$\alpha$ = 5.0 \dg}
    \label{subfig:CRMBuffetPSD5deg00}
\end{subfigure}
\caption{Surface $C_{P}$ response at $\eta$ = 0.6, and various incidences}
\label{fig:CRMBuffetUnsteadyPSD}
\end{figure}

\end{document}

These are the error messages when trying to compile the document above:

! Package subcaption Error: This package can't be used in cooperation
(subcaption)                with the subfigure package.

 ...                                              

! Missing number, treated as zero.
 
                   }
l.10 \begin{subfigure}[b]{0.5\textwidth}

? 
! Illegal unit of measure (pt inserted).
 
                   }
l.10 \begin{subfigure}[b]{0.5\textwidth}

? 

Underfull \hbox (badness 10000) in paragraph at lines 10--10
[]\OT1/cmr/m/n/8 (a)
Runaway argument?
width=\textwidth ]{CRMBuffetPSD5deg00eta0600} \caption {$\alpha $ = 5\ETC.
! Paragraph ended before \Gin@iii was complete.
 
                   \par 
l.30 

? 

! LaTeX Error: \begin{subfigure} on input line 10 ended by \end{document}.

The solution is to decide which package to use, either the subfigure or the subcaption package, but not both. (Note: The subfigure package offers a different syntax.)

Since you are using a special document class: Maybe there was an update of this class and now the subfigure package is included within this class? Please take a look if the subfigure package is used by a look into the log file, e.g.:

(/home/axel/.miktex/texmfs/install/tex/latex/subfigure/subfigure.sty
Package: subfigure 2002/07/30 v2.1.4 subfigure package