Normally, captions of a theorem-like environment are not broken across lines, because they are put into the argument of \item
by the default styles.
If one has long captions and a narrow text width this causes a problem:
the caption is running out of the right margin.
I tried to define my own theorem style which sets the caption outside of the argument to \item
.
However, this causes two drawbacks:
- It causes an unnecessary and undesired extra line break, if the first thing is another enumerate- or itemize-environment. The first fist item of the nested environment does not run into the first line
- The caption of the theorem and the theorem's body are split across pages if the first line happens to fall at the bottom of a page even if widow- and club-penalty are infinite.
I also tried to fiddle around with the internal commands \@afterheading
, \@noparitem
and \@inlabel
to remedy these drawbacks, but I had no luck.
My (not so short) 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}
The screenshots:
amsthm
instead ofntheorem
(but you need to define themyplain
style differently).