# Subcaption environment failed. All figures containing a subfigure crashing all of a sudden

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}


\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

• Your code looks fine. Possibly one of your packages was damaged, or the order was changed. – John Kormylo Jan 14 at 15:46
• First, don't panic. Try and make a minimal example, with also a pointer to the template. – egreg Jan 14 at 15:54
• thanks for your comments. @JohnKormylo is there a way to repair damaged packages? – Razvan Apetrei Jan 14 at 16:08
• If a package is damaged, the maintainer introduced a bug. It will be repaired by the maintainer (of the package or of the distribution). – Johannes_B Jan 14 at 16:55
• Neither of us know what caused the problem, it could be a change in a package, or some typo in your code. If you want a sensible advice (and not only some wild guesses) you will have to provide a complete example for tests. – Ulrike Fischer Jan 14 at 17:37

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

• Thank you for your answer. I looked into the log file and my class does not use the subfigure package, only subcaption. Is there any other recommendation? The error fixed itself overnight but now it appeared again. – Razvan Apetrei Jan 17 at 9:58
• @RazvanApetrei If the subfigure package is not used additionally a different source is defining a subfigure environment with different syntax. Could you please give us an URL where we could download the document class you are using? Otherwise we have no chance to reproduce and solve your problem. – Axel Sommerfeldt Jan 18 at 20:21
• @AlexSommerfeldt here's the link. The template also provides a "compile-thesis-windows.bat" file which I ran and then the error disappeared. LINK: github.com/kks32/phd-thesis-template/releases/tag/v2.4 – Razvan Apetrei Jan 21 at 12:52
• @RazvanApetrei compile-thesis-windows.bat deletes the intermediate files (.aux, .lof, ...) so it seems that something got into them which didn't belong there. – Axel Sommerfeldt Jan 22 at 9:08
• Thanks @AlexSommerfeldt for the clarification :) – Razvan Apetrei Jan 28 at 12:35