Optional ornament
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.
\documentclass{book}
\usepackage{lipsum}
\usepackage{fourier}
\textheight380pt
\def\PrintPageParameters{\noindent\hskip5cm\vbox{\tt
\noindent vsize: \the\vsize;\\
\noindent pagetotal: \the\pagetotal; \\
pagegoal: \the\pagegoal\\ }%
}
\def\ornament{\vspace{10pt}\hfill\aldineright\aldineleft\hfill\hfill}
\def\Chapter#1{%
\ifdim\pagetotal<350pt \PrintPageParameters\\ \ornament\chapter{#1}
\else
\chapter{#1}
\fi
}
\begin{document}
\chapter{Introduction}
\lipsum[1-4]
\Chapter{After Ornaments}
\end{document}
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.
Inspired by the code in memoir.cls and wrote this small command :
\newcommand{\ifenoughspace}[3]{%
\@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}