邊注內的虛擬文字不會繼續到下一頁

邊注內的虛擬文字不會繼續到下一頁

這是我的小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}

輸出是,

在此輸入影像描述

為什麼旁注中的虛擬文字不繼續到下一頁?

答案1

我將其作為不同的答案輸入,因為它基於該方法\vsplit並且沒有該方法的缺點paracol。請注意,需要兩次運行才能計算到文字區域底部的距離。

\marginflow被用來代替\marginpar. \marginrepeat僅用於\afterpage.

有趣的是,如果沒有所有的\newpages,這只會有 3 頁。

\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

此解決方案的缺點是您不能將“註釋”插入句子或段落的中間。

\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}

這用於\everypar在段落開頭執行切換(具有垂直偏移)。由於資訊\marginpar儲存在 aux 檔案中,因此需要運行兩次。\marginpar每段僅限一個。

\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}

相關內容