Adding an equation or formula to a figure caption in LaTeX

Posted by gotgenes on Stack Overflow See other posts from Stack Overflow or by gotgenes
Published on 2010-04-26T19:25:22Z Indexed on 2010/04/26 19:33 UTC
Read the original article Hit count: 276

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:

© Stack Overflow or respective owner

Related posts about latex

Related posts about mathematical-typesetting