# Add decoration at end of chapter

A half full page at the end of a chapter nicely signals that the chapter ends. However, sometimes the last page of a chapter looks a bit too empty if there are are only, say, 5-10 lines. In some older books you find the whitespace at the end of chapters being filled with some sort of decorative line, as in the image below.

Is there a way to define a command that measures the fill in the last page of the chapter and adds a decoration if it is more than certain length, perhaps .7\textwidth?

\documentclass{book}
\usepackage{kantlipsum}
\begin{document}
\chapter{Chapter one}
\kant[1-3]

%\decoration

\chapter{Chapter two}
\kant[1-3]

\end{document}


Here is a solution

\documentclass{book}
\usepackage{kantlipsum}
\begin{document}
\chapter{Chapter one}
\kant[1-3]

%\decoration
\ifdim\dimexpr\pagegoal-\pagetotal-\baselineskip\relax>.7\textheight
\begin{center}
\rule{3cm}{2pt}
\end{center}
\fi
\chapter{Chapter two}
\kant[1-3]

\end{document}


The following uses x,y-coordinate labels/markers to measure the end-of-chapter fill, inserting a \chapterdecoration (you can change this) whenever there's more than 70% of the \textheight remaining.

\documentclass{book}
\usepackage{kantlipsum}
\usepackage{eso-pic,zref-savepos}
\AtBeginDocument{%
\AtTextLowerLeft{%
\zsaveposy{page-bottom}% Save text lower y coordinate
}%
}%
}
\let\oldchapter\chapter
\renewcommand{\chapter}{%
\ifnum\value{chapter}>0\relax
\unskip
\zsaveposy{chap-\thechapter-y}% Save chapter's last line y coordinate
\fi
\insertchapterdecoration
\oldchapter
}
\AtEndDocument{%
\zsaveposy{chap-\thechapter-y}% Save last chapter's last line y coordinate
\insertchapterdecoration}

\newcommand{\insertchapterdecoration}{%
\ifdim\dimexpr\zposy{chap-\thechapter-y}sp-\zposy{page-bottom}sp+\baselineskip>.7\textheight
\chapterdecoration
\fi
}
\newcommand{\chapterdecoration}{%
\vfill
\noindent\makebox[\textwidth]{\rule{.3\textwidth}{5pt}}\par%
\vfill
}
\begin{document}

\chapter{Chapter one}
\kant[1-3]

\chapter{Chapter two}
\kant[1-4]

\end{document}

• Is there any advantage to this over the other answer, other than that the decoration command does not need to be manually inserted? Sep 15 '15 at 21:12