1

In the package ntheorem, there is a theorem style called break, the corresponding code defining it reads:

\newtheoremstyle{break}%
  {\item[\rlap{\vbox{\hbox{\hskip\labelsep \theorem@headerfont
          ##1\ ##2\theorem@separator}\hbox{\strut}}}]}%
  {\item[\rlap{\vbox{\hbox{\hskip\labelsep \theorem@headerfont
          ##1\ ##2\ (##3)\theorem@separator}\hbox{\strut}}}]}

I adopted this code to make it work with amsthm, below is a MWE.

\documentclass{article}

\usepackage{amsthm} \newtheoremstyle{break} {}{} {\normalfont}{} {\bfseries}{} {0pt} {% \rlap{\vbox{\hbox{% \thmname{#1}\thmnumber{\nobreakspace #2}% {\thmnote{\hspace{.4em}$($#3$)$}}% }\hbox{\strut}\vskip0pt}}% }

\theoremstyle{break} \newtheorem{theorem}{Theorem}

\usepackage{blindtext}

\begin{document}

Text

\begin{theorem} \blindtext \end{theorem}

\begin{theorem} \begin{itemize} \item text \item text \item text \end{itemize} \end{theorem}

\end{document}

enter image description here

This works perfectly and in particular works when the theorem begins with a list, which is not the case for the simple definition given in the amsthm manual:

\newtheoremstyle{break}%
  {}{}%
  {\itshape}{}%
  {\bfseries}{}%  % Note that final punctuation is omitted.
  {\newline}{}

The main problem with this simple one is that when the theorem begins with an itemize or enumerate list, one would have to write \leavevmode\vspace{-\baselineskip}, see @Mico's nice answer below. A friend of mine strongly advise me to make this automatic. Also, if one writes this in an article, when the template changes, one would have to manually remove those \leavevmode\vspace{-\baselineskip}, and even though this can be done by defining it as a separate macro and redefining it each time, it is definitely not simple and elegant.

My question is:

  1. How does this code (I mean the one in the MWE, adopted from ntheorem) work? I'm not familiar with these plain TeX macros so I don't quite understand what is going on here.
  2. You may notice that I added a \vskip0pt after \hbox{\strut}, which surprisingly adds some extra vertical space after the theorem heading (which is exactly what I wanted, though I don't know why this happens). Why would this happen?
Jinwen
  • 8,518
  • @Mico Yes, as I have stated in the question, the code there does not work well when the theorem begins with an itemize or enumerate list, one would still have to manually add \leavevmode or something like this. – Jinwen Apr 23 '22 at 07:14

1 Answers1

1

Section 4.3.1 of the user guide of the amsthm package is entitled "Theorem style break". I'll quote it here in its entirety [highlighting added]:

enter image description here enter image description here


To summarize, inserting the instructions \leavevmode and \vspace{-\baselineskip} right before \begin{enumerate} fixes the problem. It's not sufficient to insert just \leavevmode.

Speaking for myself, I think that executing \leavevmode \vspace{-\baselineskip} if and when necessary is easier than to try to adapt some code from the ntheorem package. The ntheorem and amsthm packages may share similar user-level commands such \newtheorem and \theoremstyle, but they are very different "under the hood".

enter image description here

\documentclass{article}

\usepackage{amsthm} \newtheoremstyle{break}% % see section 4.3.1 of amsthm user guide {}{}{\itshape}{}{\bfseries}{}{\newline}{} \theoremstyle{break} \newtheorem{breakthm}{Theorem}

\usepackage{lipsum,enumitem}

\begin{document}

\begin{breakthm} \lipsum[2][1-3] \end{breakthm}

\begin{breakthm} \leavevmode \vspace{-\baselineskip} \begin{itemize}[nosep] % 'nosep' is optional \item text \item text \item text \end{itemize} \end{breakthm}

\end{document}

Mico
  • 506,678
  • Yes, I am aware of this and am always using this method. But a friend of mine strongly advise me to make this automatically. Also, if I write this in the article, when the template changes, I would have to remove this \leavevmode\vspace{-\baselineskip}, and even though this can be done by defining it as a separate macro and redefining it each time, it is definitely not simple and elegant. – Jinwen Apr 23 '22 at 07:45
  • Aren't amsthm theorems still just single item lists? Thus issuing \iten starts a new line (not at pc, so haven't tested on this example) – daleif Apr 23 '22 at 07:48
  • @Jinwen - It would have been useful to state this information explicitly, in the body of the query. – Mico Apr 23 '22 at 07:48
  • @daleif - Inserting an \item instruction will create a line break. However, it will also insert an inordinate amount of vertical whitespace; that's the problem alluded to in the excerpt from the user guide shown above. – Mico Apr 23 '22 at 07:52
  • At least some of these use a zero item spacing. So I haven't had issues with it. Ahh well – daleif Apr 23 '22 at 07:54
  • @Mico Sorry for not mentioning this. But your answer is great, even though I've been using \leavevmode\vspace{-\baselineskip}, it didn't occur to me that it has been officially mentioned in the guide. Continuing my previous remark, I think from this perspective the code in ntheorem works better (of course the \newtheoremstyle there is different, but the core code can be adopted as the MWE in the question) than the simple one in amsthm. One may argue about the page breaking issue, but I've also experienced page breaks after the theorem heading with the amsthm version. – Jinwen Apr 23 '22 at 07:55
  • @Jinwen - The page breaking issue you mention is also mentioned, along with a suggestion for how to fix it, in the user guide of the amsthm package. – Mico Apr 23 '22 at 08:05
  • @Mico Thank you. I'm aware of this and I was writing this to argue that the adopted complex version's (possible page breaking after the heading) problem also happens with the simple version. – Jinwen Apr 23 '22 at 08:09
  • This answer is relevant re avoiding the page break problem: https://tex.stackexchange.com/a/307199 – barbara beeton May 18 '23 at 15:31