# How to include eqnarray in caption of figure

I want to write a set of equations in a caption of a figure. I implemented the answer of this question but it did not work out. The error I got is:

 ! Argument of \Hy@tempa has an extra }.


For example I want to write:

\begin{figure}
\includegraphics[scale=1]{test.pdf}
\caption{\leavevmode\\\begin{minipage}{\linewidth}
\begin{align}
a &= b \\ c &= d
\end{align}
\end{minipage}
}
\end{figure}


How can I do this? Thanks!

## EDIT

I want to write a text, and then write the equations. For example:

The equations are:
a = b
c = d

• Are you sure you want to number the equations? Aug 21 '15 at 15:23
• @egreg, I can simply write the equations in \begin{eqnarray*} so as not to number the equations. Aug 21 '15 at 15:26
• Don't use eqnarray! Aug 21 '15 at 15:32

You need to either \protect the minipage and the align or to use the optional argument for caption (which is a good idea if you are going to generate a list of figures to give an entry for the LoF without the equation); loading the caption package also gives you line breaks:

\documentclass{article}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{graphicx}

\begin{document}

\begin{figure}
\centering
\includegraphics[width=4cm]{example-image-a}
\caption{Some explanatory text goes here\\\protect\begin{minipage}{\linewidth}\protect\begin{align}
a &= b \\ c &= d
\protect\end{align}\protect\end{minipage}}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=4cm]{example-image-a}
\caption[text for the LoF]{Some explanatory text goes here\\\begin{minipage}{\linewidth}\begin{align}
a &= b \\ c &= d
\end{align}\end{minipage}}
\end{figure}

\end{document}


• Have you checked the equation numbers? Aug 21 '15 at 15:24
• @po6 So? Write the text. With both my solutions you can add the text. What seems to be the problem? Aug 21 '15 at 15:33
• @egreg that's up to the OP to have them or remove them. Aug 21 '15 at 15:33
• The first letter of the first word is written next to Figure 1, the others are written on a separate lines. Aug 21 '15 at 15:35
• @po6 Try \begin{figure} \centering \includegraphics[width=4cm]{example-image-a} \caption[test for the LoF]{Some text\\\protect\begin{minipage}{\linewidth}\begin{align} a &= b \\ c &= d \end{align}\protect\end{minipage}} \end{figure} \begin{figure} \centering \includegraphics[width=4cm]{example-image-a} \caption[test for the LoF]{Some text \begin{aligned}[t] a &= b \\ c &= d \end{aligned}} \end{figure} Aug 21 '15 at 15:37

I assume you don't want the display in the list of figures, so I add an empty short caption and also singlelinecheck=false from the caption package.

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{hyperref}

\begin{document}

\begin{figure}[htp]
\captionsetup{singlelinecheck=false}
\centering
\includegraphics[width=.6\columnwidth]{duck}
\caption[]{This figure illustrates some functions. The equations are
\begin{align*}
a &= b \\ c &= d
\end{align*}
}
\end{figure}

\end{document}


If you don't want the numbers, use align* instead of align; never use eqnarray. See eqnarray vs align

• Can you explain why never to use eqnarray? Aug 21 '15 at 15:29
• Aug 21 '15 at 15:30
• Can you please see the edit to the question. I want to add text before the equations. Aug 21 '15 at 15:31
• @po6 Do you need the equations in the list of figures? Aug 21 '15 at 15:37
• it doesn't matter since I do not have a list of figures. Aug 21 '15 at 15:42