我想控制定理和证明之间分页的精确惩罚。因此,我无法needspace
按照建议使用该包这里。我同时使用了amsthm
和cleveref
,因此在深入研究源代码后,我发现最终定理是由\cref@thmnoarg
和生成的。我尝试在每个定理的 之前\cref@thmoptarg
插入,但没有成功。在 之前更改为 的最大值也没有用。我在下面附上了我的代码。\nobreak
\trivlist
\@beginparpenalty
\trivlist
请注意,在期望惩罚为最大值(即\nobreak
)的特殊情况下,结果应该在第二个定理之前分页。还请注意,我确实希望定理后的惩罚较低(即150
)除非紧接着是证明。但我不知道如何实现这一点。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathptmx}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{setspace}
\let\oldtrivlist\trivlist
\makeatletter
\def\nobreaklist{\nobreak\oldtrivlist}
\patchcmd{\cref@thmnoarg}{\trivlist}{\nobreaklist}{}{}
\patchcmd{\cref@thmoptarg}{\trivlist}{\nobreaklist}{}{}
\makeatother
\usepackage{enumitem}
\newtheoremstyle{thm}{0em}{0em}{\normalfont}{0em}{\bfseries}{.}{.3em plus .3em}{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}}
\newtheoremstyle{prf}{0em}{0em}{\normalfont}{0em}{\itshape}{.}{.3em plus .3em}{\thmname{#1}\thmnote{ (#3)}}
\newlength{\thmspace}\setlength{\thmspace}{.3em plus .1em minus .1em}
\newlength{\prfspace}\setlength{\prfspace}{.3em plus .1em minus .1em}
\newcommand\thmbefore{\par\addvspace{\thmspace}\vspace{\parskip}\addpenalty{-200}}
\newcommand\prfbefore{\par\addvspace{\prfspace}\vspace{\parskip}}
\newcommand\thmafter{\par\addvspace{\thmspace}\addpenalty{-150}}
\newcommand\prfafter{\par\addvspace{\prfspace}\addpenalty{-150}}
\newcommand\thmbegin{\setlength{\parskip}{0em}}
\theoremstyle{thm}\newcommand{\theoremname}{Theorem}
\newtheorem{thm}{\protect\theoremname}
\BeforeBeginEnvironment{thm}{\thmbefore} \AfterEndEnvironment{thm}{\thmafter} \AtBeginEnvironment{thm}{\thmbegin}
\renewcommand{\proofname}{Proof}
\theoremstyle{prf}\newtheorem{prf}{\protect\proofname}
\renewenvironment{proof}[1][]{\prfbefore\begin{prf}[#1]\pushQED{\qed}}{\popQED\end{prf}\prfafter}
\setlength{\parskip}{.5em plus .3em minus .2em}
\begin{document}
\let\ea\expandafter
\def\double#1{\ea\ea\ea\def\ea\ea\ea#1\ea\ea\ea{\ea#1#1}}
\def\text{This is some text. }
\double\text \double\text \double\text \double\text
\text \par \text \par \text \par \text \par \text \par \text \par \text \par
\begin{thm} \text \end{thm}
\begin{proof} \text \end{proof}
%\penalty-3000
\begin{thm} \text \end{thm}
\begin{proof} \text \end{proof}
\end{document}