# \overleftarrow in subfigure caption

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? - add comment ## 1 Answer 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}

-
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