5

In my document, I have many large unbreakable boxes. Sometimes, the text will take up most of the page before a box that is a little too big to still fit. Consequently, I am often manually using \enlargethispage{\baselineskip} and \clearpage to adjust the page height for good page breaks. I know that I can use flexible lengths between boxes, and that would help if my boxes almost fill a page. But what if my boxes are a bit too long? Is there a way that I can tell TeX that the available page height can be stretched if it needs to?

The following illustrates what I'm having. The box is a bit too big to fit on the page. But if I shrink the bottom margin by only .1in, then the page is large enough to fit everything. I'd like to be able to specify a flexible length for the bottom margin, but the geometry package doesn't allow that to happen, and I'm not proficient enough with the page dimension lengths to be able to manually specify the appropriate spots.

\documentclass[letterpaper]{article}

\usepackage[margin=2in]{geometry} % document default causes two mostly empty pages

%\geometry{bottom=1.9in} % enlarging allows me to get one full page this time

%\geometry{bottom=2in plus 0in minus .1in}
% I'd like to keep the default, but allow it to stretch if necessary
% this command isn't valid - it acts like
%\geometry{bottom=2in}plus 0in minus .1in

\usepackage{lipsum}

\begin{document}

\lipsum[1-3]

\noindent
\fbox{\parbox[t][2in]{.97\textwidth}{large unbreakable box}}

\end{document}

There are a few other questions that deal with adjusting page dimensions and big unbreakable boxes, but the usual response ends up being that the user should manually adjust the layout. I'm wanting to find a way for TeX to automatically make the adjustments, so that I don't have to fiddle with every page. This question is close to what I'm asking about, but it's focusing on adjusting the box, not the height of the page. (And I don't understand the accepted answer.)

2 Answers 2

3

this allows an overrun of 15pt, enough in this case

enter image description here

\documentclass[letterpaper]{article}

\usepackage[margin=2in]{geometry} % document default causes two mostly empty pages

%\geometry{bottom=1.9in} % enlarging allows me to get one full page this time

%\geometry{bottom=2in plus 0in minus .1in}
% I'd like to keep the default, but allow it to stretch if necessary
% this command isn't valid - it acts like
%\geometry{bottom=2in}plus 0in minus .1in

\usepackage{lipsum}
\maxdepth=15pt
\begin{document}

\lipsum[1-3]

\noindent
\fbox{\parbox[t][2in]{.97\textwidth}{large unbreakable box}}

\end{document}
2
  • With the tcolorbox mentioned in the comments of the other answer, one probably will have to set the [baseline=15pt] to that it actually has a large depth. Nov 14, 2018 at 21:14
  • @UlrikeFischer I was misremembering - I'm using a tikzpicture to mimic a tcolorbox. But I should look into switching to tcolorbox anyway. By the way, it appears that in addition to [baseline=15pt], I'll also need \vspace{4pt} after the box to undo the baseline change.
    – Teepeemm
    Nov 15, 2018 at 18:52
1

You can use occasionally \enlargethispage{some skip}:

\documentclass[letterpaper]{article}

\usepackage[margin=2in, showframe]{geometry} % document default causes two mostly empty pages

\usepackage{lipsum}

\begin{document}

\lipsum[1-3]

\enlargethispage{1\baselineskip}
\noindent
\fbox{\parbox[t][2in]{.97\textwidth}{large unbreakable box}}

\end{document} 

enter image description here

3
  • Yes, that's my current approach. But that means I have to go through the document looking for bad breaks and manually adjusting them. And potentially remove manual adjustments that are no longer necessary. I'm hoping to offload some of that work onto the TeX page breaking algorithm.
    – Teepeemm
    Nov 14, 2018 at 19:13
  • Do you boxes really have to be unbreakable?
    – Bernard
    Nov 14, 2018 at 19:15
  • Each is a tcolorbox of a theorem or definition. So the tcolorbox prevents breaking, and from a semantic point of view the content shouldn't be broken.
    – Teepeemm
    Nov 14, 2018 at 19:32

You must log in to answer this question.

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