1

\marginnote creates a new paragraph when it's called on a separate line before a new section, which adds unwanted extra vertical space, but it doesn't do this when the next line is just a regular line:

\documentclass{article}
\usepackage{marginnote}

\begin{document}

text

\marginnote{123} % creates extra line

\section{section}

text

\marginnote{123} % doesn't create extra line

text

\end{document}

I'm trying to find a way for marginnote to not add this extra line, regardless of whether it's placed before the new section or elsewhere. marginpar doesn't do this, and works well for this specific example, but it has other drawbacks which are dealt with in marginnote, so I would prefer to fix marginnote

Technically a very similar question has already been asked and answered ( Prevent marginnote from creating extra paragraph ), but I need marginnote to not add extra paragraph when used on a separate line right before a section starts, instead of calling it from elsewhere.

1 Answer 1

2

\marginnote creates always a new paragraph. But it compensates that by inserting a negative space of \baselineskip and \parskip. This works okay with normal text but not so good if the following paragraph contains something big. E.g.

\documentclass{article}
\usepackage{marginnote}
\reversemarginpar %for the screenshot
\begin{document}

text

\marginnote{123} % doesn't create extra line

\rule{3pt}{1cm}text

\end{document}

screenshot

So the general advice is to use \marginnote only inside a paragraph.

You can use a paragraph hook to ensure that:

\documentclass{article}
\usepackage{marginnote}
\reversemarginpar
\begin{document}

text

\AddToHookNext{para/begin}{{\normalfont\normalsize\marginnote{123}}} 

\section{section}

text

\AddToHookNext{para/begin}{{\normalfont\normalsize\marginnote{456}}} 

\rule{3pt}{1cm}text

\end{document}

screenshot

1
  • Interestingly, \rule{3pt}{1cm}text example doesn't actually result in any extra vertical space for me, unlike \section. \AddToHookNext{para/begin}{{\normalfont\normalsize\marginnote{456}}} works, but it makes the next paragraph lose paragraph indentation, if used elsewhere. Commented Sep 5 at 12:16

You must log in to answer this question.

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