19

I'm trying to put a mathematics symbols in the caption of my figure with this:

\begin{figure}[!ht]
    \centering
    \includegraphics[scale=0.2]{vect_CM.png}
    \caption{Vecteur $\overrightarrow{CM}$ à un moment donné}
    \label{vect_CM}
\end{figure}

And LaTeX show an error:

Illegal parameter number in definition of \reserved@a.
<to be read again> 
                   \crcr 
l.76 ...$\overrightarrow{CM}$ à un moment donné}

Do I have to use any package to do this?

migrated from stackoverflow.com Jun 27 '14 at 13:32

This question came from our site for professional and enthusiast programmers.

22

Figure captions are considered a "movable argument" as they could end up in the List of Figures (a Table of Contents of sorts). And, such things that move end up being written to file (the .aux, .toc, .lof, ...) for use later on. This writing requires care so that certain fragile commands don't expand prematurely. \protection helps here:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{figure}[!ht]
  \caption{Vecteur $\protect\overrightarrow{CM}$ à un moment donné}
\end{figure}
\end{document}
  • Surely there is an easier way? A \captionmath that avoids having to protect everything? – AbstractDissonance Nov 27 '18 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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