7

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[caption=false]{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?

1 Answer 1

8

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}
4
  • You beat me to it, what a speed... Nice
    – user11232
    May 9, 2012 at 2:24
  • @Gonzalo Medina, Thanks for the answer. Adding an empty [] to the caption fixed the issue without using protect. \protect alone didn't help. But I have couple of questions. (1) Why this solved the problem? (2) Why did you say that the usage of \label and \subref inside \caption is strange? I have been using it like this always :)
    – suresh
    May 9, 2012 at 2:34
  • I hear about subcaption package. Is it a replacement for subfig?
    – suresh
    May 9, 2012 at 2:35
  • @suresh: for your question 1 in the comment. there is little, useful explanation in tex.stackexchange.com/questions/53536/… . For q 2, the usual practice is to put the label just after the caption. But it should not hurt if put inside. The references will break inside caption (moving argument that is used in toc etc), hence need to be protected.
    – user11232
    May 9, 2012 at 4:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .