打破页面间的定理

打破页面间的定理

我目前有这个myexample运行良好的自定义定理环境。

\newtheoremstyle{myexamplestyle}{}{}{}{}{\bfseries}{.}{ }{}
\theoremstyle{myexamplestyle}\newtheorem{myexample}{Example}

但是,您能否帮助我增强此环境,以便如果它分为两个页面,那么“示例 1(续)”显示在下一页吗?

“示例 1(续)”应出现在下一页上其自己的非缩进行/段落中,然后是下一行上示例的续篇。(该续篇可能是也可能不是新的“段落”,这取决于下一页是否开始新的段落,或者上一页的段落是否在下一页继续。换句话说,解决方案应该支持这两种情况。)

这当然不会影响其他任何东西,包括我的其他自定义定理环境和样式。


这样做的目的是,如果没有这样的东西,下一页上的新段落看起来就不像是示例的一部分。

\documentclass{article}

\usepackage{amsthm}
\newtheoremstyle{myexamplestyle}{}{}{}{}{\bfseries}{.}{ }{}
\theoremstyle{myexamplestyle}\newtheorem*{myexample}{Example}

\usepackage{lipsum}

\begin{document}

\lipsum[1-8]
Some more text for custom adjustment. Some more text for custom adjustment. Some more text for custom adjustment. Some more text for custom adjustment. Some more text for custom adjustment. Some more text for custom adjustment. Some more text for custom adjustment. Some more text for custom adjustment. 

\begin{myexample}
  \lipsum[4-5]
  A new paragraph. Is it clear that this is a part of the example?
  \lipsum[6]
\end{myexample}

Isn't the space above this paragraph somewhat confusing? The reader now has
to go back to the last page, and compare spacing, in order to finally realize
that the above paragraph was (probably) a part of the example.

\lipsum[6]

\end{document}

结果如下(尽管你看不清文字):

结果

答案1

基于包的解决方案afterpage。在环境标签的开始和结束处设置以获取页码。然后根据需要在新页面的开头添加续行文本。我已将续行文本居中。对于不同的对齐方式,\centerline可以用 替换\leftline\leftline{\kern\parindent...}用于左对齐并缩进段落,或\rightline。还可以在续行文本下方添加额外的空间,请参阅代码中的注释。

\documentclass{article}

\usepackage{amsthm}
\newtheoremstyle{myexamplestyle}{}{}{}{}{\bfseries}{.}{ }{}
\theoremstyle{myexamplestyle}
\newtheorem{myexample}{Example}

\usepackage{afterpage}
\usepackage{zref-abspage}

\makeatletter

\newcommand*{\addcontinuationsupport}[1]{%
  \expandafter\let\csname mycont@org@#1\expandafter\endcsname
      \csname#1\endcsname
  \expandafter\renewcommand\expandafter*\csname#1\endcsname{%
    \let\org@thm\@thm
    \let\@thm\mycont@thm
    \csname mycont@org@#1\endcsname
  }%
  \expandafter\let\csname mycont@org@end#1\expandafter\endcsname
      \csname end#1\endcsname
  \expandafter\def\csname end#1\endcsname{%
    \ifhmode\unskip\fi
    \zref@labelbyprops{\themycont z}{abspage}%
    \csname mycont@org@end#1\endcsname
  }%
}

% The labels at the begin and end of the environment
% get label names with the help of a counter
\newcounter{mycont}
\renewcommand*{\themycont}{mycont\the\value{mycont}}

% Cathing data from the begin part of the environment and
% smuggle \mycont@head at the beginning of the theorem
% header.
\newcommand*{\mycont@thm}[3]{%
  \def\mycont@counter{#2}%
  \def\mycont@name{#3}%
  \let\mycont@@head\mycont@head
  \org@thm{%
    #1%
    \thm@headfont\expandafter{%
      \the\thm@headfont
      \mycont@@head
      \global\let\mycont@@head\relax
    }%
  }{#2}{#3}%
}

% At the begin of the theorem add a label, get the number of
% pages and call a nested \afterpage as often as needed.
\newcommand*{\mycont@head}{%
  \stepcounter{mycont}%
  \zref@labelbyprops{\themycont}{abspage}%
  \zref@refused{\themycont}%
  \begingroup 
    \toks@={}%
    \count@=\numexpr\zref@extractdefault{\themycont z}{abspage}{0}%
      -\zref@extractdefault{\themycont}{abspage}{0}\relax
    \@whilenum\count@>\z@\do{%
      \advance\count@\m@ne
      \toks@\expandafter{%
        \expandafter\afterpage\expandafter{%
          \the\toks@
          \centerline{% centered or \leftline for flush left
          % \leftline{%
          % \leftline{\kern\parindent
            \color@begingroup
              \let\mycontHead\relax
              \the\thm@headfont
              \mycont@name
              \ifx\mycont@counter\@empty % support unnumbered theorems
              \else
                ~\csname the\mycont@counter\endcsname
              \fi
              ~(Cont.)%
            \color@endgroup
          }%
        }%  
      }%    
    }%      
    \the\toks@
  \endgroup   
}
\makeatother

\addcontinuationsupport{myexample}

\usepackage{lipsum}

\begin{document}

\lipsum[1-8]
Some more text for custom adjustment. Some more text for custom adjustment.
Some more text for custom adjustment. Some more text for custom adjustment.
Some more text for custom adjustment. Some more text for custom adjustment.
Some more text for custom adjustment. Some more text for custom adjustment.

\begin{myexample}
  \lipsum[4-5]   
  A new paragraph. Is it clear that this is a part of the example?
  \lipsum[7-12]
\end{myexample}

\textbf{After the example.}
Isn't the space above this paragraph somewhat confusing? The reader now has
to go back to the last page, and compare spacing, in order to finally
realize
that the above paragraph was (probably) a part of the example.

\lipsum[6]

\end{document}

第 3 页和第 4 页顶部

编辑:要求\addcontinuationsupport{<theorem>}添加。
编辑:增加了对未编号定理的支持。

答案2

我建议你使用\newmdtheoremenv(从mdframed包)来定义您的环境;使用middleextrasecondextra您可以轻松实现您想要的;一个小例子(图例“示例(续)”将以粗体和方框显示,但当然,您可以选择最适合您需要的格式):

\documentclass{article}
\usepackage[paperwidth=12cm,paperheight=10cm]{geometry}% JUST FOR THE EXAMPLE
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newmdtheoremenv[
  hidealllines=true,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  middleextra={%
    \node[draw,anchor=west,yshift=0.7cm] at (P-|O) {\bfseries Example~\theexample~(Cont.)};
  },
  secondextra={%
    \node[draw,anchor=west,yshift=0.7cm] at (P-|O) {\bfseries Example~\theexample~(Cont.)};
  }
]{example}{Example}

\begin{document}

\begin{example}
\lipsum[1-3]
\end{example}
\begin{example}
\lipsum[1-3]
\end{example}

\end{document}

在此处输入图片描述

当然,人们可以使用预定义样式或使用 定义自己的定理样式;这里有一个使用问题中给出的\newtheoremstyle设置的示例:myexamplestyle

\documentclass{article}
\usepackage[paperwidth=12cm,paperheight=10cm]{geometry}% just for the example
\usepackage{amsthm}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newtheoremstyle{myexamplestyle}
  {}{}{}{}{\bfseries}{.}{ }{}
\theoremstyle{myexamplestyle}
\newmdtheoremenv[
  hidealllines=true,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  middleextra={%
    \node[anchor=west,yshift=0.7cm,inner xsep=0pt] at (P-|O) {\bfseries Example~\theexample~(Cont.)};
  },
  secondextra={%
    \node[anchor=west,yshift=0.7cm,inner xsep=0pt] at (P-|O) {\bfseries Example~\theexample~(Cont.)};
  }
]{example}{Example}

\begin{document}

\begin{example}
\lipsum[1-3]
\end{example}
\begin{example}
\lipsum[1-3]
\end{example}

\end{document}

在此处输入图片描述

这是另一个选项,这次使用thmtools包作为的前端amsthm;使用这种方法,您可以定义一种样式(与定义兼容amsthm),该样式可以应用于任意数量的定理类结构(编号或未编号)。在下面的示例中,我展示了样式以及如何将其用于编号结构和未编号结构;我还展示了如何修改结构的属性,但保留“延续”样式:

\documentclass{article}
\usepackage[paperwidth=12cm,paperheight=10cm]{geometry}% just for the example
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\makeatletter
\declaretheoremstyle[
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
preheadhook={
\begin{mdframed}[hidealllines=true,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  middleextra={\node[anchor=west,yshift=2ex,inner xsep=0pt] at (P-|O) {\bfseries\thmt@thmname~\csname the\thmt@envname\endcsname
~(Cont.)};},%
  secondextra={\node[anchor=west,yshift=2ex,inner xsep=0pt] at (P-|O) {\bfseries \thmt@thmname~\csname the\thmt@envname\endcsname~(Cont.)};}%
]},
prefoothook=\end{mdframed}
]{myexamplestyle}
\makeatother
\declaretheorem[style=myexamplestyle,numbered=no]{example}
\declaretheorem[style=myexamplestyle,postheadhook=\itshape]{remark}

\begin{document}

\begin{example}
\lipsum[1-3]
\end{example}
\begin{remark}
\lipsum[1-3]
\end{remark}

\end{document}

在此处输入图片描述

另一个选择是使用\surroundwithmdframed;使用这种方法,定理及其风格通过amsthm(或ntheorem)以通常的方式定义,并在的帮助下为生成的环境赋予所需的“连续”风格mdframed

\documentclass{article}
\usepackage[paperwidth=12cm,paperheight=10cm]{geometry}% just for the example
\usepackage{amsthm}
 \usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newtheoremstyle{myexamplestyle}
  {}{}{}{}{\bfseries}{.}{ }{}
\theoremstyle{myexamplestyle}
\newtheorem*{myexample}{Example}

\surroundwithmdframed[
  hidealllines=true,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  middleextra={\node[anchor=west,yshift=2ex,inner xsep=0pt] at (P-|O) {\bfseries Example~(Cont.)};},%
  secondextra={\node[anchor=west,yshift=2ex,inner xsep=0pt] at (P-|O) {\bfseries Example~(Cont.)};}%
]{myexample}

\begin{document}

\begin{myexample}
\lipsum[1-3]
\end{myexample}

\end{document}

相关内容