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
aloha
  • 385

2 Answers2

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

Gonzalo Medina
  • 505,128
  • Have you checked the equation numbers? – egreg 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? – Gonzalo Medina Aug 21 '15 at 15:33
  • @egreg that's up to the OP to have them or remove them. – Gonzalo Medina 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. – aloha Aug 21 '15 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}`

    – Gonzalo Medina Aug 21 '15 at 15:37
  • ok, got it! The problem was that I was writing the text right after the \caption[]. Now it works, thanks for your help! – aloha Aug 21 '15 at 15:40
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

egreg
  • 1,121,712