0

If I have cases inside my caption, the compilation always gives an error

Argument of \caption@ydblarg has an extra }.

I have the following simple code. I tried various solutions such ah as the option singlelinecheck=false below, or \protect the cases, yet nothing works.

\documentclass[11pt, a4paper]{article}
\usepackage[singlelinecheck=false]{caption}
\usepackage{mathtools}
\usepackage{amsmath}

\begin{document}

\begin{figure}[h]
\includegraphics{some-image}
\caption{
  Bla bla notations; additionally,
  $
  \theta(i)= 
  \begin{cases}
      \alpha_i, & i\in A \\
      \beta_i,  & i\in B  
   \end{cases}
   $
   }
\label{fig}
\end{figure}

\end{document}
  • You need \protect\begin{cases} and \protect\end{cases}. In LaTeX releases older than 2019-10-01, \begin and \end are protected by default and your example runs fine. – Phelype Oleinik Nov 22 '19 at 12:53
  • 2
    @PhelypeOleinik LaTeX releases older than 2019-10-01? :-) – campa Nov 22 '19 at 13:01
  • 2
    @PhelypeOleinik isn't it the other way round: "in LaTeX releases younger than 2019-10-01" – daleif Nov 22 '19 at 13:01
  • 2
    while you could use \protect that isn't really the right solution, the reason for a fragile command in a moving argument error like this is the text is being moved (to the list of figures) and (almost certainly) you do not want a mult-line display in that list so use \caption[something short]{a long thing with cases} – David Carlisle Nov 22 '19 at 13:10
  • 1
    if you use \listoffigures you probably want something i that option, but it's your document. – David Carlisle Nov 22 '19 at 13:26
2

while you could use \protect that isn't really the right solution, the reason for a fragile command in a moving argument error like this is the text is being moved (to the list of figures) and (almost certainly) you do not want a multi-line display in that list so use

  \caption[something short]{a long thing with cases}

then the full version will not need \protect and will appear in the figure, and the short version will appear in the list generated at the start of the document if you use

\listoffigures
|improve this answer|||||

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.