2

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
3
  • Are you sure you want to number the equations?
    – egreg
    Aug 21, 2015 at 15:23
  • @egreg, I can simply write the equations in \begin{eqnarray*} so as not to number the equations.
    – aloha
    Aug 21, 2015 at 15:26
  • 1
    Don't use eqnarray!
    – Bernard
    Aug 21, 2015 at 15:32

2 Answers 2

3

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}

enter image description here

6
  • Have you checked the equation numbers?
    – egreg
    Aug 21, 2015 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, 2015 at 15:33
  • @egreg that's up to the OP to have them or remove them. Aug 21, 2015 at 15:33
  • The first letter of the first word is written next to Figure 1, the others are written on a separate lines.
    – aloha
    Aug 21, 2015 at 15:35
  • 1
    @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, 2015 at 15:37
3

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}

enter image description here

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

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

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.