与定理环境一致的定理装饰

与定理环境一致的定理装饰

我正在使用 documentclass 排版文档memoir。目前,我的定理具有以下定义(使用包提供的宏ntheorem):

% THEOREMS
\theoremheaderfont{\sffamily\bfseries\upshape}%
\theorembodyfont{\itshape}%
\theoremsymbol{}%
\theoremseparator{\ }%
\theoremprework{\needspace{2\baselineskip}\noindent\theoremhang\vspace*{-1.3ex}}%
\theorempostwork{\nopagebreak\noindent\theoremhung}%
\setlength{\theorempreskipamount}{-1ex}
\setlength{\theorempostskipamount}{-1ex}
\newtheorem{theorem}{Theorem}[chapter]%

其中\theoremprework\theorempostwork分别使用以下两个宏来修饰定理:

\newcommand{\theoremhang}{% top theorem decoration
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,2){\line(1,0){206}}% Top line
      \multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,-1){1}}% Top left hang
        \put(203,\iA){\line(0,-1){1}}% Top right hang
      }%
    \end{picture}%
  \endgroup%
}%

\newcommand{\theoremhung}{% bottom theorem decoration
  \nobreak
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,0){\line(1,0){206}}% Bottom line
      \multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,1){1}}% Bottom left hang
        \put(203,\iA){\line(0,1){1}}% Bottom right hang
      }%
    \end{picture}%
  \endgroup%
}%

以下是基于这些定义的定理的常见观点:

定理装饰

我遇到的问题发生在页面切换时,其中任一图形(\theoremhang\theoremhung)出现在页面末尾附近。我有时会\theoremhang在页面底部被孤立,并且不会“粘”到环境中theorem。其他时候,如果环境在页面底部结束,\theoremhung最终会在下一页上被孤立。theorem

我尝试将东西放在一起,\needspace并使用了一些负面的垂直对齐(通过\vspaces)。虽然前者可能有帮助,但后者感觉有点像黑客,而且两者都没有theorem像我希望的那样与环境保持一致。有什么想法可以解决这个问题,甚至优化这个外观吗?


为了完整起见,这里有一个最小的工作示例,包含上述定义(包括proof环境,也通过ntheorem)以及示例定理/证明:

\documentclass{memoir}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}%
\usepackage{lipsum,multido,graphicx,xcolor}

% THEOREMS
\theoremheaderfont{\sffamily\bfseries\upshape}%
\theorembodyfont{\itshape}%
\theoremsymbol{}%
\theoremseparator{\ }%
\theoremprework{\needspace{2\baselineskip}\noindent\theoremhang\vspace*{-1.3ex}}%
\theorempostwork{\nopagebreak\noindent\theoremhung}%
\setlength{\theorempreskipamount}{-1ex}
\setlength{\theorempostskipamount}{-1ex}
\newtheorem{theorem}{Theorem}[chapter]%

% PROOF
\theoremheaderfont{\sffamily\bfseries\upshape}%
\theorembodyfont{\upshape}%
\theoremstyle{nonumberplain}%
\theoremseparator{\ }%
\theoremsymbol{}%
\setlength{\theorempreskipamount}{1ex}%
\newtheorem{proof}{Proof}%

\newcommand{\theoremhang}{% top theorem decoration
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,2){\line(1,0){206}}% Top line
      \multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,-1){1}}% Top left hang
        \put(203,\iA){\line(0,-1){1}}% Top right hang
      }%
    \end{picture}%
  \endgroup%
}%

\newcommand{\theoremhung}{% bottom theorem decoration
  \nobreak
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,0){\line(1,0){206}}% Bottom line
      \multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,1){1}}% Bottom left hang
        \put(203,\iA){\line(0,1){1}}% Bottom right hang
      }%
    \end{picture}%
  \endgroup%
}%

\begin{document}
\chapter{First chapter}
\lipsum[1]

\begin{theorem}%
If~$G$ is a connected graph of order $n\geq 3$ and size~$m$, then
\[
    g(G)\geq \frac{m}{6}-\frac{n}{2}+1.%
\]

\begin{proof}%
Suppose a connected graph~$G$ of order $n\geq 3$ and size~$m$ is embedded in a surface of genus~$g(G)$, thus producing~$f$ faces. Then it follows by Theorem~XX that every face is a 2-cell and hence by Theorem~YY that $n-m+f=2-2\,g(G)$. An identical argument as in the proof of Theorem~ZZ shows that $3f\leq 2m$ and so
\[
    2-2\,g(G)=n-m+f\leq n-m+\frac{2m}{3},%
\]
from which the desired inequality follows.%
\end{proof}%
\end{theorem}%

\lipsum[2]

\end{document}

答案1

问题在于定理是列表,而列表在其开始和结束处引入了断点;当你将证明放在定理内部时,你的定理结尾有两个断点(因此防止断点需要克服这两个断点)。

最简单的方法可能是不使用列表来重写定理环境,但这意味着失去(或重写)对 ntheorem 功能的支持。而且不能保证它总是有效,因为诸如 之类的东西\[...\]也可能引入断点(但\postdisplaypenalty=10000在定理内部设置可以解决问题)。

这是一个尝试;我尝试消除所有可能的断点,但使用诸如{center}{enumerate}之类的东西{itemize}可能会引入断点(使用 enumitem 包,您可以使用密钥endpenalty=10000来防止这种情况)。此实现假设您的证明将始终在 之前结束\end{theorem}

\documentclass{memoir}

\usepackage{amsmath}
\usepackage{lipsum}
\usepackage{multido,xcolor}

\newcounter{theorem}[chapter]
\newenvironment{theorem}
  {\par\noindent\theoremhang\par\nobreak\noindent
   \refstepcounter{theorem}\postdisplaypenalty=10000 %
   {\sffamily\bfseries\upshape Theorem \thetheorem}\ \ignorespaces}
  {\par\nobreak\noindent\theoremhung\par\addvspace{\topsep}}

\newenvironment{proof}
  {\par\addvspace{\topsep}\noindent{\sffamily\bfseries\upshape Proof}\ \ignorespaces}
  {\par\nobreak}% no spacing here so that supposes you will always use {proof} inside {theorem} or else there might be some problems.

\newcommand{\theoremhang}{% top theorem decoration
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,2){\line(1,0){206}}% Top line
      \multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,-1){1}}% Top left hang
        \put(203,\iA){\line(0,-1){1}}% Top right hang
      }%
    \end{picture}%
  \endgroup%
}%

\newcommand{\theoremhung}{% bottom theorem decoration
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,0){\line(1,0){206}}% Bottom line
      \multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,1){1}}% Bottom left hang
        \put(203,\iA){\line(0,1){1}}% Bottom right hang
      }%
    \end{picture}%
  \endgroup%
}%


\begin{document}

\chapter{First chapter}
\lipsum[1]

\begin{theorem}%
If~$G$ is a connected graph of order $n\geq 3$ and size~$m$, then
\[
    g(G)\geq \frac{m}{6}-\frac{n}{2}+1.%
\]

\begin{proof}%
Suppose a connected graph~$G$ of order $n\geq 3$ and size~$m$ is embedded in a surface of genus~$g(G)$, thus producing~$f$ faces. Then it follows by Theorem~XX that every face is a 2-cell and hence by Theorem~YY that $n-m+f=2-2\,g(G)$. An identical argument as in the proof of Theorem~ZZ shows that $3f\leq 2m$ and so
\[
    2-2\,g(G)=n-m+f\leq n-m+\frac{2m}{3},%
\]
from which the desired inequality follows.%
\end{proof}%
\end{theorem}%

\lipsum[2]

\begin{theorem}%
If~$G$ is a connected graph of order $n\geq 3$ and size~$m$, then
\[
    g(G)\geq \frac{m}{6}-\frac{n}{2}+1.%
\]
\end{theorem}%

\lipsum[3]

\begin{theorem}%
\lipsum[4]
\end{theorem}%

\lipsum[5]

\end{document}

相关内容