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.

This compiles fine.

\documentclass{article}
\usepackage{subfig}
\begin{document}

test: $\overleftarrow{a}$

\begin{figure}
    %\subfloat[Subcaption $\overleftarrow{a}$]{\framebox[3cm]{First}}
    \subfloat[Subcaption $b$]{\framebox[3cm]{Second}}
\end{figure}

\end{document}

I put a Math-Mode in the caption of the subfloat. In the next example I put math mode and \overleftarrow, and although it gives the right output, it produces an error.

\documentclass{article}
\usepackage{subfig}
\begin{document}

test: $\overleftarrow{a}$

\begin{figure}
    \subfloat[Subcaption $\overleftarrow{a}$]{\framebox[3cm]{First}} \hfill
    \subfloat[Subcaption $b$]{\framebox[3cm]{Second}}
\end{figure}

\end{document}

Error:

ERROR: Illegal parameter number in definition of \sf@captionlist.
--- TeX said ---
<to be read again> 
               \crcr 
l.10 ...\overleftarrow{a}$]{\framebox[3cm]{First}}

Why is there an error?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You need to use \protect.

\documentclass{article}
\usepackage{subfig}
\begin{document}

test: $\overleftarrow{a}$

\begin{figure}
    \subfloat[Subcaption $\protect\overleftarrow{a}$]{\framebox[3cm]{First}} \hfill
    \subfloat[Subcaption $b$]{\framebox[3cm]{Second}}
\end{figure}

\end{document}
share|improve this answer
2  
See What is the difference between Fragile and Robust commands? for detailed discussion of why this is necessary. –  Andrew Swann Aug 16 '12 at 12:33
    
Thanks! This works fine –  dziadgba Aug 16 '12 at 12:34
    
@AndrewSwann --- thanks; I was just looking for a decent reference on this so as to add a link. –  Ian Thompson Aug 16 '12 at 12:36

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.