2

This is my little MWE,

\documentclass{book}

\usepackage{blindtext}

\usepackage{geometry}
    \geometry{
        includemp, % or include something else?
        paper=a4paper,
        marginparwidth=45mm
        }

\begin{document}
    Of course \marginpar{\blindtext[7]} \blindtext[7]
\end{document}

And the output is,

enter image description here

Why dummy text in the marginal note doesn't continue to next pages?

  • a marginpar is a parbox, and boxes never split across pages on their own. – David Carlisle Jun 10 '16 at 18:43
  • @DavidCarlisle How can I make it possible to split across pages? – Shaqpad Jun 10 '16 at 18:47
  • If you knew how much room you had left on the first page you could put the note into a \savebox, use \vsplit and output two margin notes. If the second doesn't automatically float to the next page, you could use \afterpage. – John Kormylo Jun 10 '16 at 19:37
  • Alternatively, you can use the paracol package and make the margin note area into a column. – John Kormylo Jun 10 '16 at 19:41
3

I'm entering this as a different answer since it is based on \vsplit and has none of the drawbacks of the paracol approach. Note that it takes two runs to compute the distance to the bottom of the text area.

\marginflow is used instead of \marginpar. \marginrepeat is only used in \afterpage.

Interestingly, without all the \newpages this will only go for 3 pages.

\documentclass{book}
\usepackage[showframe]{geometry}
    \geometry{
        includemp, % or include something else?
        paper=a4paper,
        marginparwidth=45mm
        }

\usepackage{afterpage}
\usepackage{tikzpagenodes}
\newlength{\bottom}
\newsavebox{\marginparbox}

\newcommand{\marginflow}[1]% #1 = text
 {\strut\tikz[remember picture,overlay]% compute distance to bottom of text area
    {\pgfextracty{\bottom}{\pgfpointdiff{\pgfpointanchor{current page text area}{south}}{\pgfpointorigin}}%
    \global\bottom=\bottom}%
    \advance\bottom by 0.4\baselineskip
    \parbox{\marginparwidth}{\global\setbox\marginparbox=\vbox{#1}}%
    \ifdim\bottom>\dimexpr\ht\marginparbox+\dp\marginparbox\relax
      \marginpar{\raisebox{\dimexpr 0.6\baselineskip-\height}{\usebox{\marginparbox}}}%
    \else
      \setbox1=\vsplit\marginparbox to \bottom
      \marginpar{\raisebox{\dimexpr 0.6\baselineskip-\height}{\usebox1}}%
      \ifdim\ht\marginparbox>-\dp\marginparbox
        \afterpage{\marginrepeat}%
      \fi
    \fi\ignorespaces}

\newcommand{\marginrepeat}{\vspace*{-\baselineskip}%
  \ifdim\textheight>\dimexpr\ht\marginparbox+\dp\marginparbox\relax
  \marginpar{\raisebox{\dimexpr 0.6\baselineskip-\height}{\usebox{\marginparbox}}}%
\else
  \setbox1=\vsplit\marginparbox to \textheight
  \marginpar{\raisebox{\dimexpr 0.6\baselineskip-\height}{\usebox1}}%
  \ifdim\ht\marginparbox>-\dp\marginparbox
    \afterpage{\marginrepeat}%
  \fi
\fi}

\usepackage{blindtext}

\begin{document}
So here I am going on and on about absolutely nothing when I happen to mention something which I want to 
describe in the margins HERE  \marginflow{\blindtext[7]} then continue as if nothing had happened.
\null\newpage
\null\newpage
\null\newpage
\null\newpage
\null\newpage
\end{document}
2

The drawback with this solution is that you can't just insert the "note" into the middle of a sentence or paragraph.

\documentclass{book}
\usepackage[showframe]{geometry}
    \geometry{
        includemp, % or include something else?
        paper=a4paper,
        textwidth=418.25368pt,% \the\dimexpr \textwidth+\marginparsep+\marginparwidth\relax
        marginparsep=0pt,
        marginparwidth=0pt
        }
\usepackage{paracol}
  \setcolumnwidth{\dimexpr \textwidth-45mm-\columnsep\relax,45mm}
  \twosided

\usepackage{blindtext}

\begin{document}
\begin{paracol}{2}
Of course 
\switchcolumn*\blindtext[7]\switchcolumn
as I was saying
\end{paracol}
\end{document}

This uses \everypar to perform the switch at the beginning of the paragraph (with a vertical offset). It takes two runs, since the information from \marginpar is stored in the aux file. The limit is only one \marginpar per paragraph.

\documentclass{book}
\usepackage[showframe]{geometry}
    \geometry{
        includemp, % or include something else?
        paper=a4paper,
        textwidth=418.25368pt,% \the\dimexpr \textwidth+\marginparsep+\marginparwidth\relax
        marginparsep=0pt,
        marginparwidth=0pt
        }
\usepackage{paracol}
  \setcolumnwidth{\dimexpr \textwidth-45mm-\columnsep\relax,45mm}
  \twosided

\makeatletter
\newcounter{absparagraph}
\newlength{\marginpar@offset}
\newif\ifmarginpar
\newif\ifrepeatpar

\newcommand{\newparagraph}[2]% #1 = pragraph, #2 = y location
{\expandafter\gdef\csname paragraph@#1\endcsname{#2}}

\newcommand{\newmarginpar}[3]% #1 = pragraph, #2 = y location, #3 = text
{\expandafter\gdef\csname marginpar@y@#1\endcsname{#2}%
 \expandafter\gdef\csname marginpar@text@#1\endcsname{#3}}

\renewcommand{\marginpar}[1]% #1=text
{\pdfsavepos
 \protected@write\@auxout{}{\string\newmarginpar{\theabs@paragraph}%
   {\noexpand\number\pdflastypos}{#1}}\ignorespaces}%

\newcommand{\AtBeginParagraph}{\ifmarginpar\else
  \ifrepeatpar\repeatparfalse
  \else
    \stepcounter{absparagraph}%
    \xdef\theabs@paragraph{\theabsparagraph}%
    \strut\pdfsavepos
    \protected@write\@auxout{}{\string\newparagraph{\theabs@paragraph}%
      {\noexpand\number\pdflastypos}}%
    \@ifundefined{paragraph@\theabs@paragraph}{}{%
      \@ifundefined{marginpar@text@\theabs@paragraph}{}{%
        \global\marginpar@offset=\csname paragraph@\theabs@paragraph\endcsname sp\relax
        \global\advance\marginpar@offset by -\csname marginpar@y@\theabs@paragraph\endcsname sp\relax
        \vspace{-\baselineskip}%
        \marginpartrue
        \switchcolumn*
        \vspace*{\marginpar@offset}\csname marginpar@text@\theabs@paragraph\endcsname
        \switchcolumn
        \marginparfalse\repeatpartrue}}%
  \fi
\fi}
\makeatother

\AtBeginDocument{\everypar{\AtBeginParagraph}}

\usepackage{blindtext}

\begin{document}
\begin{paracol}{2}
So here I am going on and on about absolutely nothing when I happen do mention somtehing to which I want to 
describe in the margins HERE  \marginpar{\blindtext[7]} then continue as if nothing had happened.
\end{paracol}
\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.