10

I am working with marginpar to put some comments in the margin of my document. In one case I would like to put a comment on a caption of a figure, a MWE of which looks like this:

\begin{document}
 \begin{figure}
 \caption{captiontext  \marginpar{marginText}}
 \end{figure}
\end{document}

Unfortunately, this fails saying: Argument of \@caption has an extra }

Why is this happening? And how can I fix it/work around it?

lockstep
  • 250,273
Michiel
  • 575
  • Is there a particular reason why it should be inside the environment? Since marginpar has no mark, it could just go outside of the figure environment! – Andy Nov 12 '14 at 09:12
  • @andy marginpar is actually positioned on on the same horizontal level as the position from which you call it, so that is why I would like to use it within the environment – Michiel Nov 12 '14 at 10:23
  • It only is positioned at the same level, if there are not many other marginals pushing it, e.g., down. But David Carlisle's answer also addresses this. – Andy Nov 12 '14 at 11:34

1 Answers1

5

Standard marginpars are added by the page breaker so don't work in any kind of box, so a caption or float box on its own would be a enough, a caption inside a float doubly so. Also the caption is written to the list of figures where you probably don't want the note. You could use \caption[..]{...} to have a note-less caption for the lof.

There are implementations of margin notes that do not use the output routine to add the note, for example

enter image description here

\documentclass{article}
\usepackage{marginnote}
\begin{document}
\begin{figure}
XXXXXX
\caption[zzz]{zzzz\marginnote{this}}
\end{figure}
text.. text.. text.. text.. text.. text.. text.. 
text.. text.. text.. text.. text.. text.. text.. 
text.. text.. text.. text.. text.. text.. text.. 
text.. text.. text.. text.. text.. text.. text.. 
text.. text.. text.. text.. text.. text.. text.. 
\end{document}
David Carlisle
  • 757,742
  • Great! Works like a charm. Just for future reference: if you do not include the [zzz] part for the caption, this solution actually doesn't work either. So it is not only nice to include it for the list of figures: it is necessary – Michiel Nov 12 '14 at 10:44
  • 1
    @Michiel oh well you could use \protect\marginnote if you really wanted the note also in the lof rather than use the [] argument – David Carlisle Nov 12 '14 at 10:46
  • I see, but I agree with you that you typically don't want that. – Michiel Nov 12 '14 at 10:48