0

This is a follow up to my previous question.

Some of my theorem environments include a horizontal rule above and below them.

How can I avoid the bottom line to appear isolated on the next page if the theorem is printed at the end of the page? As here:

enter image description here

The bottom hrule is the only object related to the remark that is shown on the second page, and I want to avoid it. How can I do it?

\documentclass{book}
\usepackage{amsthm,thmtools,needspace}
\declaretheoremstyle[
        headfont=\normalfont\bfseries, 
        notefont=\normalfont\bfseries,
        headpunct={},
        postheadspace=\newline,
        bodyfont = \normalfont,
        preheadhook=\vspace{\dimexpr \baselineskip + \parskip}\hrule \vspace{-\parskip},
        postfoothook= \hrule\vspace*{\dimexpr \parskip},
        spaceabove=8pt,
        spacebelow=8pt
]{mystyle2}
\declaretheorem[style=mystyle2]{remark}
\begin{document}
\chapter{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Urna id volutpat lacus laoreet. Pulvinar pellentesque habitant morbi tristique. Amet aliquam id diam maecenas. Proin libero nunc consequat interdum. Viverra suspendisse potenti nullam ac. Et molestie ac feugiat sed lectus vestibulum. Id donec ultrices tincidunt arcu non sodales neque sodales. Cras pulvinar mattis nunc sed blandit libero volutpat. Aliquet risus feugiat in ante metus dictum at. Ac turpis egestas integer eget aliquet. Nunc mi ipsum faucibus vitae. Duis ut diam quam nulla porttitor massa. Sollicitudin tempor id eu nisl nunc mi ipsum faucibus vitae. Proin nibh nisl condimentum id.

Dui vivamus arcu felis bibendum ut tristique et egestas quis. Tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero. Bibendum arcu vitae elementum curabitur. Nibh tortor id aliquet lectus. Fermentum odio eu feugiat pretium. Morbi quis commodo odio aenean sed adipiscing diam. Ac tincidunt vitae semper quis lectus nulla at. Eu facilisis sed odio morbi quis commodo odio aenean sed. Sagittis nisl rhoncus mattis rhoncus urna neque viverra justo nec. Tellus elementum sagittis vitae et leo duis. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Et magnis dis parturient montes nascetur ridiculus mus mauris.

Nulla posuere sollicitudin aliquam ultrices sagittis orci a scelerisque. Facilisi nullam vehicula ipsum a. Vitae tempus quam pellentesque nec nam aliquam. Tristique risus nec feugiat in fermentum posuere. Pulvinar elementum integer enim neque volutpat. Nunc sed blandit libero volutpat sed cras. Purus ut faucibus pulvinar elementum integer enim neque volutpat ac. Ut faucibus pulvinar elementum integer. Nunc sed augue lacus viverra vitae. Varius duis at consectetur lorem donec massa sapien faucibus. Id venenatis a condimentum vitae sapien. Sit amet mauris commodo quis imperdiet massa tincidunt. \begin{remark} This remark should not be split into twp pages! \end{remark} Gravida dictum fusce ut placerat orci nulla pellentesque dignissim enim. Mattis rhoncus urna neque \end{document}

tush
  • 1,115
  • But your remark is only one line long. If the last couple of lines were part of the remark, you could end the first line/paragraph with \par\nobreak and then the last part wouldn't break unless it's more than three lines long. – barbara beeton Oct 21 '22 at 17:50
  • Sorry, I don't understand. I am looking for a solution such as AtEndEnvironment{remark}{\needspace{3\baselineskip}}, and not manual insertions of mid-document commands. – tush Oct 21 '22 at 17:55
  • The requirement for \needspace{3\baselineskip} after every remark could very well bite you, by possibly forcing a multi-line remark to break at the end of a page when it would actually fit. What you describe seems to me to be an occasional happening rather than something regular. In such a case, individual attention is better. – barbara beeton Oct 21 '22 at 23:00
  • @barbarabeeton I think that your approach is the better one to adopt. But I am trying to insert a \par\nobreak and there is no effect. Can you elaborate on it? – tush Oct 28 '22 at 11:04

2 Answers2

1

I think that adding some shrinkability to the glue before the bottom \hrule would make TeX's job easier. As Donald Knuth states in the first paragraph of chapter 15 of the TeX book:

"If the vertical glue on a page has little or no ability to stretch or to shrink, TEX usually has no choice about where to start a new page: conversely, if there is too much variability in the glue, the result will look bad because different pages will be too irregular. Therefore if you arc fussy about the appearance of pages, you can expect to do some rewriting of the manuscript until you achieve an appropriate balance, or you might need to fiddle with the \looseness as described in Chapter 14: no automated system will be able to do this as well as you."

using \vspace instead of \vspace* after the bottom \hrule and adding 1pt of shrinkability solves this problem, but you might prefer a different glue, just fiddle with the parameters until you get a desired balance.

Here is the code:

\documentclass{book}
\usepackage{amsthm,thmtools,needspace}
\declaretheoremstyle[
headfont=\normalfont\bfseries, 
notefont=\normalfont\bfseries,
headpunct={},
postheadspace=\newline,
bodyfont = \normalfont,
preheadhook=\vspace{\dimexpr \baselineskip + \parskip}\hrule \vspace{-\parskip},
postfoothook= \hrule\vspace{\dimexpr \parskip},
spaceabove=8pt,
spacebelow=8pt minus 1pt
]{mystyle2}
\declaretheorem[style=mystyle2]{remark}
\begin{document}
    \chapter{Introduction}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Urna id volutpat lacus laoreet. Pulvinar pellentesque habitant morbi tristique. Amet aliquam id diam maecenas. Proin libero nunc consequat interdum. Viverra suspendisse potenti nullam ac. Et molestie ac feugiat sed lectus vestibulum. Id donec ultrices tincidunt arcu non sodales neque sodales. Cras pulvinar mattis nunc sed blandit libero volutpat. Aliquet risus feugiat in ante metus dictum at. Ac turpis egestas integer eget aliquet. Nunc mi ipsum faucibus vitae. Duis ut diam quam nulla porttitor massa. Sollicitudin tempor id eu nisl nunc mi ipsum faucibus vitae. Proin nibh nisl condimentum id.
Dui vivamus arcu felis bibendum ut tristique et egestas quis. Tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero. Bibendum arcu vitae elementum curabitur. Nibh tortor id aliquet lectus. Fermentum odio eu feugiat pretium. Morbi quis commodo odio aenean sed adipiscing diam. Ac tincidunt vitae semper quis lectus nulla at. Eu facilisis sed odio morbi quis commodo odio aenean sed. Sagittis nisl rhoncus mattis rhoncus urna neque viverra justo nec. Tellus elementum sagittis vitae et leo duis. Suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Et magnis dis parturient montes nascetur ridiculus mus mauris.

Nulla posuere sollicitudin aliquam ultrices sagittis orci a scelerisque. Facilisi nullam vehicula ipsum a. Vitae tempus quam pellentesque nec nam aliquam. Tristique risus nec feugiat in fermentum posuere. Pulvinar elementum integer enim neque volutpat. Nunc sed blandit libero volutpat sed cras. Purus ut faucibus pulvinar elementum integer enim neque volutpat ac. Ut faucibus pulvinar elementum integer. Nunc sed augue lacus viverra vitae. Varius duis at consectetur lorem donec massa sapien faucibus. Id venenatis a condimentum vitae sapien. Sit amet mauris commodo quis imperdiet massa tincidunt. 
\begin{remark}
    This remark should not be split into twp pages!
\end{remark}
Gravida dictum fusce ut placerat orci nulla pellentesque dignissim enim. Mattis rhoncus urna neque 

\end{document}

Udi Fogiel
  • 3,824
0

A quick way is to use minipage.

\begin{minipage}{\textwidth}
\begin{remark}
This remark should not be split into twp pages!
\end{remark}
\end{minipage}
  • 2
    Thanks, but if I type an environment with body that spans for more than one page, the content that doesn't fit into the page would be invisible. – tush Oct 21 '22 at 17:29