Undefined control sequence \subfloat

This is odd, my code was working just fine, then I literally just step out of the room and when I come back and compile I get the error undefined control sequence \subfloat.

Basically I am trying to arrange 3 images, cc.png, bb.png and tt.png in a document side by side rather than in a column as latex was trying to make it. This is the relevant section of my code:

\documentclass{article}
\usepackage[top=0.5in]{geometry}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{auto-pst-pdf}
\usepackage{epstopdf}
\usepackage{float}
\usepackage{subfloat}
\usepackage{caption}
\usepackage{axodraw4j}
\usepackage{pstricks}
\usepackage{color}

\DeclareMathSizes{10}{12}{10}{6}

\begin{document}

\title{Higgs Boson Deacay}
\author{name}
\maketitle

\begin{figure}[h!t]
\centering
\subfloat{\includegraphics[scale=0.7]{cc}}
\subfloat{\includegraphics[scale=0.7]{bb}}
\subfloat{\includegraphics[scale=0.7]{tt}}
\end{figure}

\end{document}


My output was fine and I'm sure I didn't change anything (although I concede I must have done otherwise there would be no problem) but this code now keeps giving me the error I have stated. I've looked at this for so long that the problem is probably staring me in the face but I can't see it. Any help would be greatly appreciated.

• I use subfig instead of subfloat in the package declaration, then the code goes as expected. – Jesse Jan 19 '14 at 3:23
• Thanks, this small change fixed the problem, that must be what I changed. Thanks for the other answers also. I will give subcaption a try. – Max Rodgers Jan 19 '14 at 13:12

The subfloat package doesn't define \subfloat (and has never defined it). Its purpose is different: you can group different captions under the same number with a letter attached, similarly to what the environment subequations (from amsmath) does.

For \subfloat you need to load subfig

\usepackage{subfig}


or

\usepackage[caption=false]{subfig}


if you don't want to load the caption package together with subfig (some classes, notably IEEEtran don't allow the loading of caption.

You should consider subcaption, though, if you don't have limitations on the packages you use: it's more recent and well maintained. Moreover it has not the small defects subfig shows when hyperref is used.

By the way you should not say

\begin{figure}[!ht]


(where you place ! is immaterial), but

\begin{figure}[!htp]


because otherwise you could block the float queue.

Please don't use subfloat, subfig and friends, because those have certain issues with some document classes. Here is a solution using the recent subcaption package.

Implementation

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[ht!]
\centering
\begin{subfigure}{.4\linewidth}
\includegraphics[scale=0.7]{cc}
\caption{cc}
\end{subfigure}
\hskip2em
\begin{subfigure}{.4\linewidth}
\includegraphics[scale=0.7]{bb}
\caption{bb}
\end{subfigure}
\begin{subfigure}{.4\linewidth}
\includegraphics[scale=0.7]{tt}
\caption{tt}
\end{subfigure}
\caption{Several subfigures}
\end{figure}
\end{document}


Output

• Any time I see “subfig is deprecated” I ask: by whom? No, it isn't; a manual says it, but it's wrong. The package subcaption is certainly better, but some classes do not allow it, and the safety escape is \usepackage[caption=false]{subfig}. – egreg Jan 19 '14 at 11:04
• @egreg Sorry about that. Thanks for clearing that up. I edited my answer accordingly. – Henri Menke Jan 19 '14 at 11:12

I prefer to use multiple subfigures.

For that you have to include the subcaption package declaration:

\usepackage{subcaption}


Then, the code for putting 3 figures side-by-side looks like this:

\begin{figure}[t!]
\centering
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=\textwidth]{fig1.png}
\caption{}
\label{fig:a}
\end{subfigure}
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=\textwidth]{fig2.png}
\caption{}
\label{fig:b}
\end{subfigure}
\begin{subfigure}[b]{0.25\textwidth}
\centering
\includegraphics[width=\textwidth]{fig3.png}
\caption{}
\label{fig:c}
\end{subfigure}
\caption{Three images side-by-side}
\end{figure}