5

I have a marginnote within a figure caption:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{geometry}
\usepackage{marginnote}

\begin{document}

\begin{figure}[h]
\begin{center}
%\includegraphics{a.png}
\caption{
  This image shows something unusual.
  {\marginnote{ORLY?}[0cm]}
}
\end{center}
\end{figure}

\end{document}

This compiles fine (without the {} around the \marginnote it fails), but still produces an error in the logs (which is very annoying in a multi-user overleaf project):

! Argument of \@caption has an extra }.
<inserted text>
                \par
l.16 }

? Runaway argument?
! Paragraph ended before \@caption was complete.
<to be read again>
                   \par
l.16 }

How can I fix this error?

1 Answer 1

8

Fragile command in a moving argument.

Either use the optional argument (without margin note) of \caption or prefix with \protect.

In the latter case, the margin note will also appear in the list of figures.

\documentclass{article}
\usepackage{marginnote}

\begin{document}

\begin{figure}[htp]
\centering

\caption[This image shows something unusual]{%
  This image shows something unusual.\marginnote{ORLY?}[0cm]%
}

\end{figure}

\begin{figure}[htp]
\centering

\caption{%
  This image shows something unusual.\protect\marginnote{ORLY?}[0cm]%
}

\end{figure}

\end{document}

Don't forget to protect endlines in order to avoid unwanted spaces. Also center is not really wanted in figure as it would add vertical space before and after the float.

enter image description here

You must log in to answer this question.

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