1

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:

  1. 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
  2. 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:

Page #1 with most problems Page #4 and #5 with undesired page break

1
  • The problem doesn't show up if I use amsthm instead of ntheorem (but you need to define the myplain style differently). – egreg Aug 16 '20 at 14:16
2

The issue is inherent to ntheorem.

If I use amsthm together with the interface provided by thmtools, the issue is solved.

\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}

enter image description here

1
  • Unfortunately, I use a lot of other packages which depend on ntheorem. Probably, it might be possible to switch to amsthm but not with a lot of effort and time which I do not have until publication. So a (quick) fix for ntheorem would be welcomed. – nagmat84 Aug 16 '20 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.