嵌套环境中的特殊分页问题

嵌套环境中的特殊分页问题

我一直在尝试创建自定义定理环境,因为经典的 newtheorem 命令不适合我的需求。我遇到了分页符问题,下面我将对此进行解释。代码如下:

\documentclass[12 pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{fullpage}
\usepackage[framemethod=tikz]{mdframed}

\renewenvironment{proof}
    {\par
    \textit{\underline{Proof.}} \par
    \nopagebreak
    \vspace{12 pt}% 
            \begin{mdframed}[bottomline=false,topline=false,rightline=false]%
}
{%
    \end{mdframed}\par
    \vspace{-15 pt}%
    \begin{flushright} $\square$ \end{flushright}%
}

\begin{document}
Text

\vspace{550 pt}

Text
    \begin{proof}
        This text goes on the next page without the title "\textit{\underline{Proof.}}", and I would want my environment title to stick with its body. 
    \end{proof}
\end{document}

有办法解决这个问题吗?我花了好几个小时在 Google 上搜索,但还是想不出办法。

编辑:我设法通过简单地使用 mdframed 包来摆脱那个愚蠢的中间环境。不过,仍然用这个确切的代码得到了分页符。

答案1

你缺少一些%,并且至少想要一个\nopagebreak

\renewenvironment{proof}
{\par
    \textit{\underline{Proof.}}\par
    \nopagebreak
    \vspace{12 pt}%
    \begin{proofline}%
}
{%
    \end{proofline}%
    \vspace{-15 pt}%
    \begin{flushright} $\square$ \end{flushright}%
}

proofline您可能需要更多,这取决于您未显示的定义。


如果您要防止在自然位置分页,则需要允许前一页上有可拉伸的白色空间来“填补空白”,但在这种情况下,这还不够,因为分页发生在内部,mdframed所以最简单的方法是用它needspace来检查页面上有多少空间,如果太靠近底部,则强制分页。

\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{fullpage}
\usepackage{needspace}
\usepackage[framemethod=tikz]{mdframed}

\renewenvironment{proof}
    {\par
    \pagebreak[1]%
    \vspace{0pt plus \fill}%
    \needspace{5\baselineskip}%
    \textit{\underline{Proof.}} \par
    \nopagebreak
    \vspace{12 pt}% 
    \nopagebreak
            \begin{mdframed}[bottomline=false,topline=false,rightline=false]%
    \nopagebreak
}
{%
    \end{mdframed}\par
    \vspace{-15 pt}%
    \begin{flushright} $\square$ \end{flushright}%
}

\begin{document}
Text

\vspace{550 pt}

Text
    \begin{proof}
        This text goes on the next page without the title "\textit{\underline{Proof.}}", and I would want my environment title to stick with its body. 
    \end{proof}
\end{document}

相关内容