3

I need to write some margin notes in my tex file which I would like to have displayed in the right hand side of the page.

There is already a nice package that does that by default called margin notes which seems right for the job.

Is it, however, possible for all margin-notes which are destined to appear together on the same page to be stacked neatly, one above the other, near the center (alternatively, top, or bottom) of that margin.

Consider the following output pdf whose tex file is given beneath the picture (with some long passages of dummy text removed for the sake of clarity) Is it possible to have the two margin-notes stacked neatly on top of each other in the order of their appearance but near the center (or top or bottom...) of the margin.

I would like the solution to work for an arbitrary number of margin-notes on the same page, not just two.

enter image description here

\documentclass[12pt]{article}
\usepackage{marginnote}
\usepackage{blindtext}
\begin{document}

\section*{Notes for My Paper}

....
mollis nec, sagittis eu, wisi.  Phasellus lacus.  Etiam laoreet quam
\marginnote{ This is a margin-note}[0cm]. Sed arcu. Phasellus at dui
in ligula molli....

 .....

Aliquam erat volutpat.  Nunc eleifend leo vitae magna.  In 
iderat non orci commodo lobortis. \marginnote{ This is another 
margin-note}[0cm] Proin neque massa, cursus ut, gravida....

\end{document}

The following picture is what I would like (new position of text marked in red and different font to distinguish between the previous situation and what I need )

enter image description here

  • 3
    The purpose for marginnote is contrary to what you want to achieve. It is designed to place the marginnote exactly at the height of the line it is called in. – Skillmon May 27 '18 at 8:24
  • One way to achieve this would be to save all marginnotes into some list (e.g. expl3 clist) and at end of page (e.g. at shipout) modify the shipout box to shift the stacked one (e.g. using coffins or simple boxes) half the text height up. – TeXnician May 27 '18 at 8:43
1

Use the memoir class (which covers the book, report and article classes) (> texdoc memoir Page notes) and the \sidebar macro.

\documentclass[...]{memoir}
\usepackage{lipsum}
\begin{document}
Some text. \sidebar{Marginal note}

More text. \sidebar{Another note}

\lipsum[1]

Yet more text. \sidebar{Third note}
\end{document}

which will put the texts of each \sidebar into the margin, starting at the top and working towards the bottom. If there are too many to fit on a page then they will continue onto the next page. Read the documentation for more details.

2

This solution accumulates the marginnotes into a savebox. I did not attempt to implement all the optional arguments of \marginnote.

\documentclass[12pt]{article}
%\usepackage{marginnote}
\usepackage{blindtext}
\usepackage{everypage}
\usepackage{showframe}% MWE only

\newsavebox{\marginbox}
\newcommand{\marginstyle}{\raggedright}
\newcommand{\marginnote}[1]% #1 = text to appear in marginpar area
{\parbox{\marginparwidth}{\marginstyle% set width etc.
  \ifdim\ht\marginbox>0pt
    \global\setbox\marginbox=\vbox{\unvbox\marginbox
      \vspace{\dimexpr\baselineskip-\ht\strutbox}% adjust spacing between notes
      #1\strut}%
  \else
    \global\setbox\marginbox=\vbox{#1\strut}%
  \fi
}}

\makeatletter
\AddEverypageHook{\dimen0=\dimexpr \oddsidemargin+\textwidth+\marginparsep\relax
  \if@twoside\ifodd\value{page}\else
    \dimen0=\dimexpr \evensidemargin-\marginparsep-\marginparwidth\relax 
  \fi\fi
  \rlap{\hspace{\dimen0}\raisebox{\dimexpr -\topmargin-\headheight-\headsep-\height}[0pt][0pt]%
    {\parbox[c][\textheight][c]{\marginparwidth}{\unvbox\marginbox}}}%
}
\makeatother

\begin{document}

\section*{Notes for My Paper}

....
mollis nec, sagittis eu, wisi.  Phasellus lacus.  Etiam laoreet quam
\marginnote{ This is a margin-note}. Sed arcu. Phasellus at dui
in ligula molli....

 .....

Aliquam erat volutpat.  Nunc eleifend leo vitae magna.  In 
iderat non orci commodo lobortis. \marginnote{ This is another 
margin-note} Proin neque massa, cursus ut, gravida....

\end{document}

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.