Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an equation or formula to a figure caption in LaTeX

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:

  • Adding a caption to an equation in LaTeX (the reverse of this question)
like image 546
gotgenes Avatar asked Apr 26 '10 19:04

gotgenes


People also ask

How do you add captions in LaTeX?

It's really easy, just add the \caption{Some caption} and inside the braces write the text to be shown. The placement of the caption depends on where you place the command; if it's above the \includegraphics then the caption will be on top of it, if it's below then the caption will also be set below the figure.

How do you add a caption above a figure in LaTeX?

It is always good practise to add a caption to any figure or table. Fortunately, this is very simple in LaTeX. All you need to do is use the \caption{text} command within the float environment.


1 Answers

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{...}.

like image 58
Rehj Cantrell Avatar answered Sep 23 '22 09:09

Rehj Cantrell