0

Background

I'm using a theorem style where there is a new line between the title and the statement.

\newtheoremstyle{simple}
{}{}
{\normalfont}{}
{\normalfont}{}
{\newline}
{{\thmname{#1}\nobreakspace\thmnumber{#2}}
  {\thmnote{\hspace{.4em}\ensuremath{(\text{#3})}}}\smallskip}

To effectively prevent page break following the title, I decided to put it inside a transparent tcolorbox where one can use the key breakable and set lines before break = 3. (The reason that I chose to adopt this complicated method is that those "normal" solutions I've found, like in this question, does not work quite well.)

I have succeeded in producing such a box and wrapping the environment within it. However, I was not able to reproduce the exact vertical spaces before and after a theorem. My guessed value was \topsep+\parskip, which is smaller than the actual value (I also tried e.g. \thm@preskip and \thm@postskip, but they seem to be 0pt).

Is there some way to access to the exact value of these vertical spaces?

(The goal is to produce the same result, except for page breaking point, with or without the extra tcolorbox.)


Note: the question actually has little to do with tcolorbox. The thing I'm interested is the exact value of these two lengths:

enter image description here


Below is a MWE. You can comment and uncomment the ExplSyntax part (which wraps a tcolorbox around the environment theorem) to see the difference.

\documentclass{article}

\usepackage{geometry} \usepackage{amsthm}

\newtheoremstyle{simple} {}{} {\normalfont}{} {\normalfont}{} {\newline} {{\thmname{#1}\nobreakspace\thmnumber{#2}} {\thmnote{\hspace{.4em}\ensuremath{(\text{#3})}}}\smallskip}

\theoremstyle{simple}

\newtheorem{theorem}{Theorem}

\ExplSyntaxOn

\PassOptionsToPackage { many } { tcolorbox } \RequirePackage { tcolorbox } \cs_new_protected:Nn \minimclass_box_environment:n { \hook_gput_code:nnn { env/#1/before } { minimalist } { \begin { tcolorbox } [ enhanced~jigsaw, frame~hidden, interior~hidden, top = 0pt, bottom = 0pt, left = 0pt, right = 0pt, boxrule = 0pt, boxsep = 0pt, before~skip = \topsep+\parskip, after~skip = \topsep+\parskip, breakable, lines~before~break=3, ] } \hook_gput_code:nnn { env/#1/after } { minimalist } { \end { tcolorbox } } } \minimclass_box_environment:n { theorem }

\ExplSyntaxOff

\usepackage{blindtext}

\begin{document}

\blindtext

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

\blindtext

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

\begin{proof} \blindtext \end{proof}

\end{document}

Jinwen
  • 8,518
  • On the top of my head I can't think of any better way than manually measuring/read the source code of tcolorbox. – user202729 Apr 03 '22 at 12:57
  • (that having said there may be some easier way to forbid line break there than tcolorbox e.g. \nopagebreak, which seems extremely overkill here) – user202729 Apr 03 '22 at 12:58
  • @user202729 Yes, but I failed with \nopagebreak - there are questions on this site about applying \nopagebreak in this theorem style, but the result is not quite satisfying. Also, I think the problem is not quite related to tcolorbox, the only thing left is to know the correct value of the vertical spaces produced by amsthm, and then one needs to insert the right value as parameters to tcolorbox. – Jinwen Apr 03 '22 at 13:02
  • „To effectively prevent page break following the title“ – isn't that what \@afterheading is for? Also, the needspace package comes to mind. – cgnieder Apr 03 '22 at 13:11
  • @cgnieder Yes, I have noted this in the question. About a month ago I tried the \@afterheading approach but it didn't work in the testing document (unfortunately I didn't keep it), so I switched to this more complicated method, which at least can be guaranteed to always work. – Jinwen Apr 03 '22 at 13:15
  • Here's an earlier answer that was mainly directed at something else, but it addresses the page break: Itemizing theorem body This really should be built into amsthm, but I'm not optimistic. I'm not experienced in using tcolorbox so can't help with that, and don't have time to test. – barbara beeton Apr 03 '22 at 13:42
  • @barbarabeeton I think I have misstate the question, as tcolorbox is not actually quite related to the real question. I have reformulated my question to emphasis the point, i.e., the value for the vertical spaces before and after a theorem. – Jinwen Apr 03 '22 at 13:53
  • These spaces are set with dimensions defined with "internal" names: \def\thm@space@setup{% \thm@preskip=\topsep \thm@postskip=\thm@preskip } You should be able to find the value of \topsep – barbara beeton Apr 03 '22 at 14:01
  • @barbarabeeton Thank you. Then it is strange, as it was exactly \topsep that I have been using, but it seems narrower than the actual value. I must have missed something. – Jinwen Apr 03 '22 at 14:07
  • Maybe tcolorbox makes some additional changes to the value being given to it. This one you probably have to read tcolorbox source code? – user202729 Apr 03 '22 at 18:34

0 Answers0