7

I have a figure in LaTeX with a caption to which I need to add a formula (equation* or displaymath environments). For example:

\documentclass[12pt]{article}
\begin{document}
\begin{figure}[tbph]
    \begin{center}
        %...
    \end{center}
    \caption{As you can see
            \begin{displaymath}4 \ne 5\end{displaymath}
    }
    \label{fig:somefig}
\end{figure}
\end{document}

This makes pdflatex angry, though it will produce a PDF.

! Argument of \@caption has an extra }.
<inserted text> 
                \par 
l.9    }

What's the right way to go about adding an equation to a figure caption?

NOTE: Please do not suggest simply using the $ ... $ math environment; the equation shown is a toy example; my real equation is much more intricate.

See also:

Community
  • 1
  • 1
gotgenes
  • 38,661
  • 28
  • 100
  • 128
  • 1
    It looks like what you're trying to do would look pretty ugly. I'd endorse displaying the equation separately, either before or after the figure and `\ref` it in the caption... – Seamus Jul 20 '10 at 12:35

2 Answers2

10

Using the package "caption":

\begin{figure}
\begin{center}
    ...
    \captionsetup{singlelinecheck=off}
    \caption[.]{
    \begin{displaymath}
        assoc\_meaning(\lambda x_{SBJ}. followed(x,y) \&actor(x) \nonumber \&actor(y),\lambda x_{SBJ}. maintained(x,\nonumber <(dist\_from(y),1))
    \end{displaymath}}
\end{center}
\end{figure}

The square brackets following \caption aren't optional, but leaving them off won't cause an error that looks any different than the one before you added \usepackage{caption} and \captionsetup{...}.

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
Rehj Cantrell
  • 261
  • 2
  • 6
2

I'm not sure why you do not want to use the $ ... $ solution, because of fractions?

If so, you can use \dfrac instead of \frac.

I would try $ \displaystyle \dfrac{1}{2} \cdot \sum_{i=0}^n i$, i.e. use the \displaystyle command.

phimuemue
  • 34,669
  • 9
  • 84
  • 115
  • http://stackoverflow.com/questions/2660044/typesetting-latex-fraction-terms-to-be-larger-in-an-equation contains an example of the type of formula I will include in the caption. Note that it is quite large and should not be in-lined with text. – gotgenes Apr 26 '10 at 19:33
  • 3
    Oh, I see. Then I would suggest to define a `\label` for the whole equation/formula and reference to it in the caption using `\eqref`, I think that's better than including such a huge formula into a figure caption. – phimuemue Apr 26 '10 at 19:36