当多行公式中间出现分页符时添加边注

当多行公式中间出现分页符时添加边注

得益于amsmath\allowdisplaybreaks宏,可以让分页符随意放置在任何位置,甚至可以放置在多行方程的中间(例如来自环境align)。

  • 优点\allowdisplaybreaks否则(禁止在多行方程式中间分页),文档很可能包含非常丑陋的未满垂直盒子。
  • 缺点\allowdisplaybreaks“我们对这个案例中的所有方程式都没有看法”,正如仅允许从偶数页到奇数页的显示中断

为了减少上述缺点,一种解决方案是在多行方程式中出现分页符时添加边注(包含类似“方程式在下一页后面”的内容)。

是否有可能实现这样的结果,例如对于环境而言align

编辑

这是我想要实现的 MWE,手动获取很容易,但我希望自动获取。它包含一个脚注和一个浮动图,以指出位于页面底部(右侧)的边注是不够的,因为它可能远离方程断开的线。

\documentclass{report}
\usepackage{amsmath}
\usepackage{mwe}
\usepackage{marginnote}
\usepackage[papersize={130mm,140mm},margin=30mm]{geometry}

\allowdisplaybreaks

\newcommand{\eqcont}{\tiny(Cont.\ next page)}

\begin{document}
Foo\footnote{\tiny\lipsum[1]}
\begin{multline}
  x = abcdefghijklmopqrstuvwyz                    \\
   + abcdefghijklmopqrstuvwyz                     \\
   + abcdefghijklmopqrstuvwyz                     \\
   + abcdefghijklmopqrstuvwyz                     \\
   + abcdefghijklmopqrstuvwyz                     \\
   + abcdefghijklmopqrstuvwyz                     \\
   + abcdefghijklmopqrstuvwyz\marginnote{\eqcont} \\
   + abcdefghijklmopqrstuvwyz                     \\
   + abcdefghijklmopqrstuvwyz                     \\
   + abcdefghijklmopqrstuvwyz
\end{multline}

\begin{figure}[b]
  \centering
  \includegraphics[height=1cm]{image-a}
    \caption{A nice figure}
    \label{nice-figure}
\end{figure}

\begin{align}
  1 + 1 & = 2                     \\
  2 + 1 & = 3                     \\
  3 + 1 & = 4                     \\
  4 + 1 & = 5                     \\
  5 + 1 & = 6                     \\
  6 + 1 & = 7\marginnote{\eqcont} \\
  7 + 1 & = 8                     \\
  8 + 1 & = 9                     \\
  9 + 1 & = 10
\end{align}
\end{document}

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

答案1

也许是这样的:

在此处输入图片描述

我已经使用过\appto(和\csappto)来自电子工具箱ifInAlignalign和环境中设置和取消设置布尔标志align*(其他环境可以以完全相同的方式完成)。这个想法是,\ifInAlign当您在环境中时为真align,否则为假。然后,使用背景包我为每个页面添加了“背景文本”,如下所示

\ifInAlign\tiny Equation continues...\fi

也就是说,Equation continues...Align环境延伸到整个页面时我们才能看到东西,否则我们什么也看不到。

完整代码如下:

\documentclass{article}
\usepackage{amsmath}
\usepackage[papersize={100mm,80mm}, margin=20mm]{geometry}% to get short pages

\newif\ifInAlign\InAlignfalse% to determine if we're inside an align environment

\usepackage{etoolbox}
\appto\align{\global\InAligntrue}% InAlign true at start of align
\csappto{align*}{\global\InAligntrue}% InAlign true at start of align*
\appto\endalign{\global\InAlignfalse}% InAlign false at end

\usepackage{background}% add continued note when InAlign
\backgroundsetup{angle=0,
  scale=1,
  color=black,
  position={0.68\textwidth,-0.95\textheight},
  contents={\ifInAlign\tiny Equation continues...\fi}
}

\everymath{\allowdisplaybreaks[4]}% turn on display breaks, always!
\begin{document}

  \begin{align}
      0 + 1 &= 1\\% some deep multi-lined aligned equations
      1 + 1 &= 2\\
      2 + 1 &= 3\\
      3 + 1 &= 4\\
      4 + 1 &= 5\\
      5 + 1 &= 6\\
      6 + 1 &= 7\\
      7 + 1 &= 8\\
      8 + 1 &= 9\\
      9 + 1 &= 10\\
      10 + 1 &= 11\\
      11 + 1 &= 12\\
      12 + 1 &= 13\\
      13 + 1 &= 14\\
      14 + 1 &= 15\\
      15 + 1 &= 16\\
      16 + 1 &= 17\\
      17 + 1 &= 18\\
      18 + 1 &= 19\\
      19 + 1 &= 20
  \end{align}

\end{document}

为了保证公式跨页显示,我使用了几何学包使得页面尺寸非常小。

答案2

好的,我成功了,希望我没有忘记可能的副作用。以下 MWE 包含解释该方法的注释(稍后,我将尝试给出expl3它的风味)。

编辑

\\我的原始代码在外部环境的文本模式下使用时出现错误,tabular因为在多行方程环境的末尾,\\它被全局重新定义为这些环境内的那个,这与默认值不同。

\documentclass{report}
\usepackage{amsmath}
\usepackage{mwe}
\usepackage{etoolbox}
\usepackage{refcount}
\usepackage{xifthen}
\usepackage{marginnote}
\usepackage[papersize={130mm,140mm},margin=30mm]{geometry}

\allowdisplaybreaks

\newcommand{\eqcont}{\tiny(Cont.\ next page)}

% Each multiline equation will have a unique number.
\newcounter{multilineeq}
% Each line of a multiline equation will have a unique number (local
% to the multiline equation).
\newcounter{lineofmultilineeq}[multilineeq]

\makeatletter
% We globally store the original double backslash in a macro
\global\let\original@double@backslash\\
% We define the patched macro of the double backslash one
\newcommand{\patched@double@backslash}{%
  % We increment the counter of the current line.
  \stepcounter{lineofmultilineeq}%
  % We set the label of the current line.
  \ltx@label{\lineofmultilineeq@label}%
  % If (and only if) the pageref of the next line if greater than the
  % current line's one, we insert a marginal note telling the equation
  % continues on next page.
  \ifthenelse{%
    \cnttest{%
      \getpagerefnumber{\nextlineofmultilineeq@label}%
    }{>}{%
      \getpagerefnumber{\lineofmultilineeq@label}%
    }%
  }{%
    \marginnote{\eqcont}%
  }{}
  % We break the line with the original double backslash macro.
  \original@local@double@backslash%
}
% We define a hack to be applied at the beginning of each multiline equation
% environment (currently, only `align(*)' and `multline(*)').
\def\beginhack{%
  % We set the unique number that has the current multiline equation.
  \stepcounter{multilineeq}
  % The number that has the 1st line of the current multiline equation is 1.
  \stepcounter{lineofmultilineeq}
  % We globally define the strings of the labels identfying:
  % - the current line,
  % - the line following the current one,
  % of the current multiline equation.
  \gdef\lineofmultilineeq@label{multilineeq-\themultilineeq-line-\thelineofmultilineeq}
  \gdef\nextlineofmultilineeq@label{multilineeq-\themultilineeq-line-\the\numexpr\thelineofmultilineeq+1}
  % We set the label of the current line.
  \ltx@label{\lineofmultilineeq@label}
  % Within the current multiline equation, we patch the double backslash macro
  % (for more details, see https://tex.stackexchange.com/a/59117/18401).
  \ifundef{\original@local@double@backslash}{%
    \global\let\original@local@double@backslash\\%
    \global\let\\\patched@double@backslash%
  }{}
}
% We define a hack to be applied at the end of each multiline equation
% environment (currently, only `align(*)' and `multline(*)').
\def\endhack{%
  % We globally unpatch the double backslash macro
  \global\let\\\original@double@backslash%
  \global\undef\original@local@double@backslash
}
\makeatother

\appto\align{\beginhack}
\csappto{align*}{\beginhack}
\appto\endalign{\endhack}
%
\appto\multline{\beginhack}
\csappto{multline*}{\beginhack}
\appto\endmultline{\endhack}

\begin{document}
Foo\footnote{\tiny\lipsum[1]}
\begin{multline}
  x = abcdefghijklmopqrstuvwyz \\
   + abcdefghijklmopqrstuvwyz  \\[1cm]
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz  \\
   + abcdefghijklmopqrstuvwyz
\end{multline}

Foo\\Bar.

\begin{tabular}{l}
Foo\\Bar.
\end{tabular}

\begin{figure}[b]
  \centering
  \includegraphics[height=1cm]{example-image-a}
  \caption{A nice figure}
  \label{nice-figure}
\end{figure}

\begin{align}
  1 + 1 & = 2 \\
  2 + 1 & = 3 \\
  3 + 1 & = 4 \\
  4 + 1 & = 5 \\
  5 + 1 & = 6 \\
  6 + 1 & = 7 \\
  7 + 1 & = 8 \\
  8 + 1 & = 9 \\
  1 + 1 & = 2 \\
  2 + 1 & = 3 \\
  3 + 1 & = 4 \\
  4 + 1 & = 5 \\
  5 + 1 & = 6 \\
  6 + 1 & = 7 \\
  7 + 1 & = 8 \\
  8 + 1 & = 9 \\
  1 + 1 & = 2 \\
  2 + 1 & = 3 \\
  3 + 1 & = 4 \\
  4 + 1 & = 5 \\
  5 + 1 & = 6 \\
  6 + 1 & = 7 \\
  7 + 1 & = 8 \\
  8 + 1 & = 9 \\
  1 + 1 & = 2 \\
  2 + 1 & = 3 \\
  3 + 1 & = 4 \\
  4 + 1 & = 5 \\
  5 + 1 & = 6 \\
  6 + 1 & = 7 \\
  7 + 1 & = 8 \\
  8 + 1 & = 9 \\
  9 + 1 & = 10
\end{align}
\end{document}

相关内容