TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to typeset my captions in margin using marginpar and captionof. Here is what I get by the MWE. Note the wrong caption numbers. Wrong caption numbering

The first caption is included using macro \fixedmarginpar and the second caption using \marginpar. The figure number gets incremented by 2 for every caption included using \fixedmarginpar.

Please read vspace-in-marginpar-adds-unwanted-vertical-space for the \fixedmarginpar macro used in MWE. This macro sets the caption in a box, and offsets the vertical alignment depending on the height of the box. The caption number is incremented by two because this macro sets a box with caption for calculating the height (\captionof is called for the first time) and then sets it in the marginpar (\captionof is called again). Whats a good workaround?


share|improve this question
up vote 10 down vote accepted

The figure number is stepped every time twice, because you're typesetting the caption twice. You can avoid this by typesetting it only once:

  \setbox0=\vtop{\parindent=0pt \hsize=\marginparwidth#2}%
  \marginpar{\vspace{\dimexpr-\ht0+#1}\box0 }%

In this way the box used for the measuring is not retypeset, but directly used.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.