[Tex/LaTex] IEEEtran, subfig clash

captionsieeetranincompatibilitysubfloats

The following code which uses the IEEEtran class, and subfig produces compile errors like, "argument of caption has an extra }", or "TeX capacity exceeded" etc. But the moment I comment out the \subref in the caption all errors vanish.

\documentclass[final]{IEEEtran}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\begin{figure*}
\centering
\subfloat[][\label{validation}Validating the model]{
\includegraphics{validationBlock.pdf}
}\\
\subfloat[][\label{a} my caption a]{
\includegraphics{validationMN.pdf}
}\\
\subfloat[][\label{b} my caption b]{
\includegraphics{piOutMN.pdf}
}\hfill
\subfloat[][\label{c}my caption c]{
\includegraphics{majorityVoterOutMN.pdf}
} 
\caption{\label{validationMN}
\subref{validation} % if i comment this line every thing is okay
my main caption
}
\end{figure*}
\end{document}

Any suggestions?

Best Answer

I find this use of \label and \subref inside \caption somehow strange; are you sure you need to use that kind of construct? If you really need to keep this construction, you will need to \protect the fragile \subref command:

\documentclass[final]{IEEEtran}
\usepackage[caption=false]{subfig}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure*}
\centering
\subfloat[][\label{validation}Validating the model]{
\includegraphics{validationBlock.pdf}
}\\
\subfloat[][\label{a} my caption a]{
\includegraphics{validationMN.pdf}
}\\
\subfloat[][\label{b} my caption b]{
\includegraphics{piOutMN.pdf}
}\hfill
\subfloat[][\label{c}my caption c]{
\includegraphics{majorityVoterOutMN.pdf}
} 
\caption{\label{validationMN}
\protect\subref{validation} % if i comment this line every thing is okay
my main caption
}
\end{figure*}
\end{document}

or to use the optional argument for \caption:

\documentclass[final]{IEEEtran}
\usepackage[caption=false]{subfig}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure*}
\centering
\subfloat[][\label{validation}Validating the model]{
\includegraphics{validationBlock.pdf}
}\\
\subfloat[][\label{a} my caption a]{
\includegraphics{validationMN.pdf}
}\\
\subfloat[][\label{b} my caption b]{
\includegraphics{piOutMN.pdf}
}\hfill
\subfloat[][\label{c}my caption c]{
\includegraphics{majorityVoterOutMN.pdf}
} 
\caption[text for LoF]{\label{validationMN}
\subref{validation} % if i comment this line every thing is okay
my main caption
}
\end{figure*}
\end{document}