2

I am trying to insert dispay-style math in the caption of a float, but I get an error.

Here is a minimal example:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{table}[t]
  \caption[short caption]{long caption with math
    \begin{equation*}
      1 \neq 0
    \end{equation*}
  }
  \label{tab:label}
  \begin{tabular}{ccc}
    1 & 2 & 3
  \end{tabular}
\end{table}
\end{document}

In this case I get

Missing $ inserted

or if I leave out the optional short version

Argument of \@caption has an extra }

I understand that the problem could be that the equation* environment is "fragile", and I need to protect it before using in the argument of a caption. I haven't been able to do it. Is it possible to obtain this somehow? Thanks for your help.

  • What if you replace \begin{equation*}1 \neq 0 \end{equation*} by $1 \neq 0$ ? – Jérôme Dequeker Oct 19 '16 at 10:54
  • 2
    More or less the same underlying issue as tex.stackexchange.com/questions/334752/…: you can't use display maths here as there is a box construct. $\displaystyle ...$ should work – Joseph Wright Oct 19 '16 at 10:56
  • @JosephWright Indeed, using inline math and \displaystyle could be a possible workaround. But I would like to have it on a newline. I tried with \\, \newline or even with an empty line, but I always end up with the equation on the same line of the text. – Marco Oct 19 '16 at 14:22
1

Normally \caption first tries to fit the caption into one line by putting it into an \hbox. Even if it doesn't fit, you will still get error messages from the attempt. If you want to reduce the width of the caption, put it inside a minipage.

\documentclass{article}
\usepackage{mathtools}
\usepackage[singlelinecheck=false]{caption}

\begin{document}
\begin{table}[t]
  \caption[short caption]{
    long caption with math
    \begin{equation*}
      1 \neq 0
    \end{equation*}
  }
  \label{tab:label}
  \begin{tabular}{ccc}
    1 & 2 & 3
  \end{tabular}
\end{table}
\end{document}

demo

  • Thanks! Indeed, the problem was the check performed by \caption to fit the caption in a single line. singlelinecheck=false solves this. – Marco Oct 20 '16 at 23:31

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.