Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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}
share|improve this answer
    
You beat me to it, what a speed... Nice –  Harish Kumar May 9 '12 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 '12 at 2:34
    
I hear about subcaption package. Is it a replacement for subfig? –  suresh May 9 '12 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. –  Harish Kumar May 9 '12 at 4:17
    
@HarishKumar thanks! –  suresh May 9 '12 at 6:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.