通常,定理类环境的标题不会跨行,因为它们被\item
默认样式放入了参数中。如果标题很长,而文本宽度很窄,则会导致问题:标题超出右边距。
我尝试定义自己的定理风格,将论证之外的标题设置为\item
。然而,这会导致两个缺点:
- 如果第一个是另一个枚举或逐项环境,则会导致不必要的和不希望的额外换行符。嵌套环境的第一个第一项不会进入第一行
- 如果第一行恰好位于页面底部,那么定理的标题和定理的主体就会跨页拆分,即使寡妇惩罚和俱乐部惩罚是无限的。
我也尝试摆弄内部命令\@afterheading
来\@noparitem
弥补\@inlabel
这些缺陷,但没有成功。
我的(不太短的)MWE:
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{ntheorem}
% Solely to format the MWE on TeX.SX:
\usepackage[paperwidth=200pt,paperheight=500pt,margin=2pt]{geometry}
\thispagestyle{empty}
\pagestyle{empty}
\widowpenalty=10000
\clubpenalty=10000
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
%
% This theorem style is mostly equivalent to the plain style.
% Only the optional heading (##3) has been moved out of the argument to item
% in order to enable line breaks.
% I need a better solution for this, see test examples below.
%
\makeatletter
\newtheoremstyle{myplain}{%
\item[\hskip\labelsep \theorem@headerfont ##1\ ##2]%
{\theorem@headerfont\theorem@separator\hskip\labelsep}\nobreak%
}{%
\item[\hskip\labelsep \theorem@headerfont ##1\ ##2]%
{\theorem@headerfont(##3)\theorem@separator\hskip\labelsep}\nobreak%
}
\makeatother
\theoremstyle{myplain}
\newtheorem{mytheorem}{Theorem}
\begin{document}
\begin{theorem}
This is a trivial theorem using the default plain style.
\end{theorem}
\begin{mytheorem}
This is a trivial theorem using the custom plain style.
There is a little bit more horizontal space between the header and the
body.
But this is acceptable and does not to be fixed.
\end{mytheorem}
\begin{theorem}[Short Caption]
This is a theorem with a short caption using the default plain style.
\end{theorem}
\begin{mytheorem}[Short Caption]
This is a theorem with a short caption using the custom plain style.
\end{mytheorem}
\begin{theorem}[A Very Long and Elaborate Caption]
This is a theorem with a long caption using the default plain style.
\textbf{\emph{Error:} The caption must be broken across lines}
\end{theorem}
\begin{mytheorem}[A Very Long and Elaborate Caption]
This is a theorem with a long caption using the custom plain style.
Even a long caption poses is no problem.
\end{mytheorem}
\begin{theorem}[With Enum]
\begin{enumerate}
\item The first item
\item The second item
\end{enumerate}
The first item runs into the same line as the header.
This is OK.
But the vertical spacing between the second item and the remaining text is
wrong.
\end{theorem}
\begin{mytheorem}[With Enum]
\begin{enumerate}
\item The first item
\item The second item
\end{enumerate}
The enumeration starts on a new line.
\textbf{\emph{Error:} This is intelligible, because the caption is outside
the item, but it needs a fix.}
\end{mytheorem}
\cleardoublepage
\vspace*{463pt}
\begin{theorem}[Page Break]
\begin{enumerate}
\item Club and widow penalties are effective
\end{enumerate}
The header of the theorem and the first line are kept together.
\end{theorem}
\cleardoublepage
\vspace*{463pt}
\begin{mytheorem}[Page Break]
\begin{enumerate}
\item Club and widow penalties show no effect
\end{enumerate}
The header of the theorem and the first line are broken across pages.
\textbf{\emph{Error:} This needs a fix.}
\end{mytheorem}
\end{document}
截图:
答案1
这一问题是 固有的ntheorem
。
如果我amsthm
与提供的接口一起使用thmtools
,问题就解决了。
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsthm}
\usepackage{thmtools}
% Solely to format the MWE on TeX.SX:
\usepackage[paperwidth=200pt,paperheight=500pt,margin=2pt]{geometry}
\thispagestyle{empty}
\pagestyle{empty}
\widowpenalty=10000
\clubpenalty=10000
\newtheorem{theorem}{Theorem}
\declaretheoremstyle[
spaceabove=\topsep,
spacebelow=\topsep,
headfont=\normalfont\bfseries,
notefont=\normalfont\bfseries,
bodyfont=\normalfont\itshape,
headpunct=,
]{myplain}
\theoremstyle{myplain}
\newtheorem{mytheorem}{Theorem}
\begin{document}
\begin{theorem}
This is a trivial theorem using the default plain style.
\end{theorem}
\begin{mytheorem}
This is a trivial theorem using the custom plain style.
There is a little bit more horizontal space between the header and the
body.
But this is acceptable and does not to be fixed.
\end{mytheorem}
\begin{theorem}[Short Caption]
This is a theorem with a short caption using the default plain style.
\end{theorem}
\begin{mytheorem}[Short Caption]
This is a theorem with a short caption using the custom plain style.
\end{mytheorem}
\begin{theorem}[A Very Long and Elaborate Caption]
This is a theorem with a long caption using the default plain style.
\textbf{\emph{Error:} The caption must be broken across lines}
\end{theorem}
\begin{mytheorem}[A Very Long and Elaborate Caption]
This is a theorem with a long caption using the custom plain style.
Even a long caption poses is no problem.
\end{mytheorem}
\begin{theorem}[With Enum]
\begin{enumerate}
\item The first item
\item The second item
\end{enumerate}
The first item runs into the same line as the header.
This is OK.
But the vertical spacing between the second item and the remaining text is
wrong.
\end{theorem}
\begin{mytheorem}[With Enum]
\begin{enumerate}
\item The first item
\item The second item
\end{enumerate}
The enumeration starts on a new line.
\textbf{\emph{Error:} This is intelligible, because the caption is outside
the item, but it needs a fix.}
\end{mytheorem}
\cleardoublepage
\vspace*{463pt}
\begin{theorem}[Page Break]
\begin{enumerate}
\item Club and widow penalties are effective
\end{enumerate}
The header of the theorem and the first line are kept together.
\end{theorem}
\cleardoublepage
\vspace*{463pt}
\begin{mytheorem}[Page Break]
\begin{enumerate}
\item Club and widow penalties show no effect
\end{enumerate}
The header of the theorem and the first line are broken across pages.
\textbf{\emph{Error:} This needs a fix.}
\end{mytheorem}
\end{document}