[Tex/LaTex] Wrong number using label in subfloat with subfig and caption=false

cross-referencingieeetrannumberingsubfloats

I'm using the IEEEtran class, and I need to use the subfig package with the caption=false option. However, when I use the package like this

\documentclass{article}
% Remove the caption=false and this work as intended
\usepackage[font=footnotesize,caption=false]{subfig}

\begin{document}

\begin{table}
\caption{My tables}
\centering
\begin{tabular}{cc}
\subfloat[\label{tab:1}]{%
\begin{tabular}{lc}
\hline\noalign{\smallskip}
a & b\\
\hline\noalign{\smallskip}
foo & bar\\\hline\noalign{\smallskip}
\end{tabular}%
}&%
\subfloat[]{%
\begin{tabular}{lc}
\hline\noalign{\smallskip}
a & b\\
\hline\noalign{\smallskip}
foo & bar\\\hline\noalign{\smallskip}
\end{tabular}%
\label{tab:2}
}%subfloat
\end{tabular}
\end{table}

Testing a reference to \ref{tab:1} and \ref{tab:2}.        
\end{document}

I obtain the reference to 2a and 2b instead of 1a and 1b. However, if I remove the caption=false everything works fine. But, I'm require to use that part, so the IEEEtran class can put the correct formatting to the captions.

What solution do I have? I tried to move the \label around, as you can see in both cases, but both have the same result.
Am I missing something here?

Best Answer

A dirty trick is to load the caption package before the document class. That way the subfig package is happy, and the document class settings that format captions overwrite those of the caption package.

\RequirePackage{caption}
\let\abovecaptionskip\relax
\let\belowcaptionskip\relax
\documentclass{IEEEtran}
\usepackage{subfig}
\begin{document}
\begin{table}
\caption{My tables}
\label{table1}
\centering
\begin{tabular}{cc}
\subfloat[]{%
\begin{tabular}{lc}
\hline\noalign{\smallskip}
a & b\\
\hline\noalign{\smallskip}
foo & bar\\\hline\noalign{\smallskip}
\end{tabular}%
\label{tab:1}
}&%
\subfloat[]{%
\begin{tabular}{lc}
\hline\noalign{\smallskip}
a & b\\
\hline\noalign{\smallskip}
foo & bar\\\hline\noalign{\smallskip}
\end{tabular}%
\label{tab:2}
}%subfloat
\end{tabular}
\end{table}
Testing a reference to \ref{tab:1} and \ref{tab:2}.        
\end{document}