# Error using subcaption

I've used the subcaption package in the past without any problem. But now, i can't use it, which makes it impossible to compile some important documents.

If i try to compile

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage[skip=0cm,list=true,labelfont=it]{subcaption}
\begin{document}
\begin{figure}[hptb]
\centering
\begin{tabular}{l l}
\subfloat[\label{fig:g1} Figura 1]
{\resizebox{0.45\textwidth}{!}{\includegraphics{img_a}}} &
\subfloat[\label{fig:g2} Figura 2]
{\resizebox{0.45\textwidth}{!}{\includegraphics{img_a}}} \\
\end{tabular}
\caption{Figure caption.}
\end{figure}
\end{document}


i get the error:

! Undefined control sequence.
l.14 \subfloat
[\label{fig:g1} Figura 1]


From the file log:

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian) (format=latex 2012.9.18)
Package: caption 2012/02/19 v3.2f Customizing captions (AR)
Package: caption3 2012/01/12 v1.4b caption3 kernel (AR)
Package: subcaption 2012/01/12 v1.1d Sub-captions (AR)


Any idea on what the problem might be?

-
\subfloat appears in the subcaption package just in an error message testing if it is defined and saying subcaption may mot be used with subfig. If you comment out the subcaption line and replace it with \usepackage{subfig} it runs without error, don't know what layout you intended though.... –  David Carlisle Sep 18 '12 at 0:18
Thanks. That solved the problem (for now, at least, and that's what i needed)... See the comment to cmhughes for more details. –  joão gândara Sep 18 '12 at 0:59

I think there's a bit of confusion here. The subcaption defines the subfigure environment, but the \subfloat command comes from the subfig package.

Personally, I'd recommend sticking with the subcaption package, and using a set up like the following for your MWE

MWE

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage[skip=0cm,list=true,labelfont=it]{subcaption}
\begin{document}
\begin{figure}[hptb]
\begin{subfigure}{.45\textwidth}
\includegraphics[width=\textwidth]{img_a}
\caption{First subfigure}
\label{fig:g1}
\end{subfigure}%
\hfill
\begin{subfigure}{.45\textwidth}
\includegraphics[width=\textwidth]{img_a}
\caption{Second subfigure}
\label{fig:g2}
\end{subfigure}
\caption{Figure caption.}
\end{figure}
\end{document}


Note that the subfigure environment takes a mandatory <width> argument, which I have specified as .45\textwidth (what you used in your MNWE). The subfigure environment can also take the same optional arguments that the minipage argument can take.

This now means that the resizebox command for your images should be used with \textwidth which will match the width of the subfigure environment.

Using this approach also means that you can remove your tabular approach.

-
You could simplify your MWE in two ways: First, you don't need the \centering statement since the two subfigures are spread apart as much as is possible. Second, instead of \resizebox{\textwidth}{!}{\includegraphics{img_a}}, it may be more straightforward to write \includegraphics[width=\textwidth]{img_a}. –  Mico Sep 18 '12 at 0:57
Yes. There was some confusion here. The problem is that i have a very large document (from where i got the MNWE) which compiled fine just a few months ago. The MNWE still compiles fine on a machine with an older TeX Live (2009). And that's where the problem came from...But thanks to you and David Carlisle for the quick and helpful solutions. I'll mark your answer as accepted, because i think it is better for new documents. But i'll go with David Carlisle suggestion, cause it is easier and quicker for a large existing document. –  joão gândara Sep 18 '12 at 1:05
@Mico thanks a lot; you're absolutely right- have made edits :) –  cmhughes Sep 18 '12 at 1:08
@joãogândara ok, no problem :) –  cmhughes Sep 18 '12 at 1:09