1

I use the marginnote package to create, well, margin notes. However, I observe some unwanted behavior when adding a note directly after a section heading, or between section headings. It seems like the command creates an empty paragraph, which is undesired, since it leads to extra whitespace or indentation.

MWE:

\documentclass{article}
\usepackage{marginnote}

\begin{document}

\section{Testsection}
\marginnote{Oops! Some extra whitespace.}
\subsection{Testsubsection}
But at least no indentation.

\section{Testsection2}
\subsection{Testsubsection2}
\marginnote{hi there!}Some extra indentation

\section{Testsection3}
\subsection{Testsubsection3}
Nothing \marginnote{Move along.} to see here.

\section{Testsection4}
\subsection{Testsubsection4}
\leavevmode\marginnote{Move along.}This also works.

\end{document}

Creates

MEW output

I have read \marginnote leads to paragraph indentation, so I know about the \leavevmode solution. However, this does not fix the first case (adding extra whitespace when between section headings).

Is there a way to define a command that will always keep marginnote from creating extra paragraphs, so I can use it where I want without thinking about it?

  • 1
    This kludge will fix it: \section[Testsection]{Testsection\protect\marginnote{\normalsize\mdseries No extra whitespace.}} – Steven B. Segletes Jun 17 '16 at 13:38
4

It seems like marginnote really wants to be used mid paragraph, but this works:

enter image description here

\documentclass{article}
\usepackage{marginnote}

\begin{document}

\section[Testsection]{Testsection\marginnote{\normalsize\normalfont
 Oops! Some extra whitespace.}}
\subsection{Testsubsection}
But at least no indentation.

\section{Testsection2}
\subsection{Testsubsection2}
%a marginpar bug \marginnote{hi there!}Some extra indentation
Some\marginnote{hi there!} extra indentation

\section{Testsection3}
\subsection{Testsubsection3}
Nothing \marginnote{Move along.} to see here.

\section{Testsection4}
\subsection{Testsubsection4}
\leavevmode\marginnote{Move along.}This also works.

\end{document}
  • 1
    I beat you by a minute with my comment, but +1 anyhow – Steven B. Segletes Jun 17 '16 at 13:40
  • Thanks, but I'd rather do \newcommand{\robustmarginnote}[1]{\domagic\marginnote{#1}}, so I can use robustmarginnote wherever I want. But maybe domagic doesn't exist, in which case your answer is of course correct. – Dion Jun 17 '16 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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