Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

\documentclass{scrreprt}
\usepackage{calc}
%http://tex.stackexchange.com/questions/78519/vspace-in-marginpar-adds-unwanted-vertical-space
\newcommand{\fixedmarginpar}[2][0pt]{%
  \setbox0=\vtop{#2}\marginpar{\vspace{\dimexpr-\ht0+#1}#2}%
}
\begin{document}
\listoffigures

\fixedmarginpar{\captionof{figure}{A}}
\marginpar{\captionof{figure}{A}}
\end{document}
share|improve this question

1 Answer 1

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:

\newcommand{\fixedmarginpar}[2][0pt]{%
  \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

 
discard

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.