12

Similar to putting a tikzpicture inside a \caption{}, I would like to insert an external icon inside figure captions, something like:

\begin{figure}
\caption{text with \includegraphics{icon} somewhere inside}
\includegraphics{image}
\end{figure}

How might this be done?

1
  • Can you please post an image of a sample of what you want to achieve?
    – yannisl
    Commented May 2, 2012 at 5:21

1 Answer 1

18

You need to protect \includegraphics inside \caption; this, however, will add the image also to a possible list of figures, so perhaps you would rather use the optional argument of \caption; in this case, no protection is needed. The following example code shows both alternatives:

\documentclass{article}
\usepackage[demo]{graphicx}% demo option just for the example

\begin{document}

\listoffigures

\begin{figure}
  \centering
  \caption{text with \protect\includegraphics[height=1cm]{icon} somewhere inside}
  \includegraphics{image}
\end{figure}

\begin{figure}
  \centering
  \caption[text for the LoF]{text with \includegraphics[height=1cm]{icon} somewhere inside}
  \includegraphics{image}
\end{figure}

\end{document}

enter image description here

1
  • that answers my question perfectly. Both options worked, either using the \protect command or including the \caption[LoF]{} format. Thanks!
    – proge
    Commented May 2, 2012 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .