[Tex/LaTex] Undefined control sequence \subfloat – using subcaption

subcaptionsubfloats

I get the same error as in this question, however I had already switched from the subfig package to subcaption a while back. I am trying to recompile a TeX file on Linux that was fine before on OS X.

So I find this in my class file:

% \usepackage{subfig} % --- this replaces subfigure 
\usepackage{subcaption} % --- this replaces subfig

I look into the subcaption documentation, and in §3.4.4 it does mention the \subfloat command.

Reading other Stackexchange posts on this, I gather that many people believe subcaption does not define subfloat while others insist they do get that command. My interpretation from this is that perhaps subfloat was part of a specific version of subcaption and maybe was removed later?

Best Answer

This old code…

\begin{figure}
\centering
\subfloat[sub-caption1]{
  \includegraphics{...}
  \label{fig:sub1}
}
\subfloat[sub-caption2]{
  \centering\includegraphics{...}
  \label{fig:sub2}
}
\caption{main caption}
\label{fig:main}
\end{figure}

…can be roughly rewritten as

\begin{figure}
\centering
\begin{subfigure}{0.48\textwidth}
  \centering\includegraphics{...}
  \caption{sub-caption1}\label{fig:sub1}
\end{subfigure}
\begin{subfigure}{0.48\textwidth}
  \centering\includegraphics{...}
  \caption{sub-caption2}\label{fig:sub2}
\end{subfigure}
\caption{main caption}
\label{fig:main}
\end{figure}

Note that you have to find suitable width parameters and use additional \centering commands, otherwise the captions are left-aligned now.