For chapters that end with a mostly empty page, I'd like to insert some form of ornament. The ornament should not be inserted if there is not enough room in the page. Is there some way of testing available vertical space?

(I don't need any help for inserting the ornament per se, only with testing the availability of vertical space in the current page. What I want to avoid is the ornament ending up all by itself on a useless otherwise blank page.)

  • It should be possible to adjust the answers to How to define a figure size so that is consume the rest of a page? for this. You just need to test if the remaining space is sufficient. – Martin Scharrer May 10 '11 at 18:52
  • Just to be able to answer that in the best possible way: Do you already know how to insert the ornament itself, i.e. is it an image, or do you need help with this? – Martin Scharrer May 10 '11 at 18:55
  • Are you going to insert it manually, or do you have some criterion of "badness" by which it is to be done automatically? – Emre May 10 '11 at 19:11
  • 1
    The problem is to have some criterion of "badness" to insert the ornament automatically, so that I don't have to worry if the text is reformatted. – David Monniaux May 10 '11 at 19:32

Since TeX does not understand chapters or sections we can only carry a test when typesetting the next chapter heading i.e., when we type \chapter.

So before we typeset the new chapter heading we examine the remaining space of the page. If there is enough space left on the page we introduce an ornament otherwise we just print the chapter heading.

  \noindent vsize: \the\vsize;\\
  \noindent pagetotal: \the\pagetotal; \\
  pagegoal: \the\pagegoal\\ }%
  \ifdim\pagetotal<350pt \PrintPageParameters\\ \ornament\chapter{#1}  
\Chapter{After Ornaments}

This will not work for the last chapter of the Book, but perhaps at that point you might want a different type of ornament.

I kept the macro '\Chapter as simple as possible in order to demonstrate the technique. One would need to extend it to cater for the starred version of the command.

  • 1
    there are problems in your code for limit cases. You see it if you change to \lipsum[1-6], but there are other problems if the page is nearly filled-up but not quite (I believe 350pt is too much, it works better with 330pt). For better portability, you should probably be testing if \dimexpr\pagegoal-\pagetotal\relax is >50pt rather than if \pagetotal is < 330pt as it would work with arbitrary \textheight. And 50pt should probably be replaced by the measured height of the ornamental stuff. – Philippe Goutet May 11 '11 at 8:00
  • @Philippe Thanks for the comments. I originally had the code with a calculation based on the remaining space, but decided to hard code the values to keep the code more understandable and yes one should integrate the height of the ornament or image in the calculation. However, the main idea I wanted to convey was that the only marker that is available is the next chapter command that the user types. I will edit the code later to add your suggestion as a separate block. – Yiannis Lazarides May 11 '11 at 13:13

Inspired by the code in memoir.cls and wrote this small command :

  \@tempdimc\pagegoal \advance\@tempdimc-\pagetotal%
  \ifdim #1>\@tempdimc #3 \else #2\fi}

Usage: \ifenoughspace{length}{what to do if enough space}{what to do otherwise}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.