# Automatic positioning of marginpar (to avoid page overflow)

I am using marginpar to margin notes in a book. My problem is that if I add a \marginpar too close to the bottom of a page, the margin will overflow the bottom of the page.

For instance, using the following code, the margin not is not fully visible as it overflows (see below).

\documentclass{article}
\usepackage{lipsum}
\begin{document}

\lipsum[1-5]
\marginpar{\tiny \lipsum[1-1]}
\end{document}


Of course, I could manually modify the place of margins like this:

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\marginpar{\tiny \lipsum[1-1]}
\lipsum[3-5]
\end{document}


But this requires moving all \marginpar each time I change a paragraph in the document. Ideally, I would prefer if latex could automatically move my marginpar up to avoid overflowing the bottom of the page.

Question: Is there a way to ask latex to place marginpar automatically? (like the arguments [t] or [h] of figure). Or should I used another package? (marginnote?)

The result that I do not want:

What I would prefer:

For my document, I am using the scrbook and classicthesis but the problem also occurs with the class article.

Does this code solve your problem?

\documentclass{article}
\usepackage{lipsum}
\newcommand{\bmarginpar}[1]{\marginpar{\parbox[b]{\marginparwidth}{\tiny#1}}}

\begin{document}

\lipsum[1-5]
\bmarginpar{\lipsum[1]}

\lipsum[6-10]

\end{document}


• Thanks, this works. – N. Gast Oct 1 at 12:39
• I just modified your command to make it work with the style of classithesis, which ends up: \newcommand{\bmarginpar}[1]{\marginpar[% {\parbox[b]{\marginparwidth}{\flushright\footnotesize\textit{#1}}}]{% \parbox[b]{\marginparwidth}{\flushleft\footnotesize\textit{#1}}}} – N. Gast Oct 1 at 12:40
• That's fine! Of course, you must have not too many margin notes in a page – it is not as automatic as one could hope. – Bernard Oct 1 at 12:44

The memoir class (an extension to book, report and article classes) provides a \sidebar{<text>} macro whereby <text> is written in the margin starting near the top of the textblock. If <text> is long it may continue onto the next page(s). Several \sidebars can be used on a page, printed in order and continuing on to further pages if necessary. The manual (> texdoc memoir) has more details on how to control which margin, fonts, spacing, etc.