1

I made a new theorem environement for a document but when the theorem is at the end of a page Latex cut the title and the core of the theorem in two pages. How can I prevent that (I can't put \ \ * instead of \newline as an argument for puncthead, I get errors).

\documentclass[10pt,a4paper]{article}
\title{Test}

\usepackage{amsmath}
\usepackage{amsthm, thmtools}

\declaretheoremstyle[
spaceabove=6pt, 
spacebelow=6pt, 
headfont=\normalfont\bfseries, 
notefont=\em\mdseries, 
notebraces={(}{)}, 
headpunct={},
bodyfont=\itshape, 
postheadspace=\newline]{theorem}

\declaretheorem[style=theorem, numbered=no,
name=Theorem, 
refname={theorem,theorems}, 
Refname={Theorem,Theorems}]{theorem}
3
  • 2
    could you fix your example to be an example of the issue, so people can test answers, currently it loads a lot of unrelated packages and has \end{document} with no \begin so it is hard to use to test anything. Commented Oct 25, 2018 at 20:18
  • Thank you for your concern, I modified a bit but Skillmon gave a good solution anyway!
    – WrabbitW
    Commented Oct 25, 2018 at 20:39
  • @WrabbitW your modification did make things worse, imho. It is still not testable with your code. You should've included a usage example (like the \begin{document}...\end{document} block from my answer) instead of just removing the \end{document}.
    – Skillmon
    Commented Oct 26, 2018 at 8:57

1 Answer 1

3

You could use the option headformat instead of postheadspace and there include \@afterheading (or anything else that is supposed to forbid page breaks there):

\documentclass[10pt,a4paper]{article}
\title{Test}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsthm, thmtools}
\usepackage{lmodern}

\makeatletter
\declaretheoremstyle[
spaceabove=6pt, 
spacebelow=6pt, 
headfont=\normalfont\bfseries, 
notefont=\em\mdseries, 
notebraces={(}{)}, 
headpunct={},
bodyfont=\itshape, 
headformat=\NAME\ \NOTE\\\@afterheading,
]{theorem}
\makeatother

\declaretheorem[style=theorem, numbered=no,
name=Theorem, 
refname={theorem,theorems}, 
Refname={Theorem,Theorems}]{theorem}

\begin{document}
\rule{\linewidth}{.95\textheight}
\begin{theorem}[note]
  This is some content, just to check whether everything works out as we want it
  to.
\end{theorem}
\end{document}

With headformat and \@afterheading:

enter image description here

Your version of the setup (just to show that there would be a page break):

enter image description here

6
  • Thank you it works perfectly! If you have time could you explain the commands \NAME and \NOTE\\@afterreading please?
    – WrabbitW
    Commented Oct 25, 2018 at 20:29
  • @WrabbitW \NAME and \NOTE are used by thmtools as place holders for the name and the note of the theorem (there additionally is \NUMBER, but since those are not numbered I left that one out). \@afterheading is defined by the LaTeX kernel and is added after section titles and stuff. It should prevent page breaks (and has some other things it's supposed to do, e.g. to prevent indentation of the first paragraph, etc.)
    – Skillmon
    Commented Oct 25, 2018 at 20:32
  • I don't understand why \@afterreading works and \* is not supported?
    – WrabbitW
    Commented Oct 25, 2018 at 20:41
  • @WrabbitW it's \@afterheading not \@afterreading :) \\* works by using \nobreak which sets the penalty for a page break very high (10000, the biggest TeX supports). \@afterheading sets \everypar to set the club penalty to 10000 for the first paragraph, so works differently internally. The rest is TeX magic :)
    – Skillmon
    Commented Oct 26, 2018 at 9:02
  • If I got it right the penalty is the distance between two lines or pages that Latex tries to minimize. So by setting it to 10000 it let latex think that even if the space between Theorem and the core text is big (for example when it have to change page) Latex still thinks it's a one piece block?
    – WrabbitW
    Commented Oct 26, 2018 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .