Figure Placement – How to Place a Figure at the End of Each Chapter Only if There’s Room in LaTeX

bookschaptersfigure-placement

MWE:

\documentclass[12pt,openany]{book}
\usepackage{stackengine}
\usepackage{lipsum}
\usepackage{graphicx}

\def\asterism{\par\vspace{1.6em}{\centering\scalebox{2.00}{%
  \stackon[-0.5pt]{\bfseries*~*}{\bfseries*}}\par}\vspace{.5em}\par}

\begin{document}
\large

\chapter*{CHAPTER 1.}
\thispagestyle{empty}
\lipsum[3]
\begin{figure*}[b]
  \asterism
\end{figure*}

\chapter*{CHAPTER 2.}
\lipsum[3-4]
\begin{figure*}[b]
  \asterism
\end{figure*}
\end{document}

which produces:

enter image description here

which is fine. But, also—

enter image description here

(which is not fine)

QUESTION: How may I place a figure (such as the asterism shown) at the bottom of the last page of each chapter (only if there's room)? So, in the case of the MWE, I would only want to display the figure (asterism) at the end of the first chapter only.

Thank you.

Best Answer

You could probably use hooks instead of \chapterend.

\documentclass[12pt,openany]{book}
\usepackage{stackengine}
\usepackage{lipsum}
\usepackage{graphicx}
%\usepackage{showframe}

\newsavebox{\asterism}
\savebox\asterism{\parbox[b]{\textwidth}{\vspace{1.6em}\centering\scalebox{2.00}{%
  \stackon[-0.5pt]{\bfseries*~*}{\bfseries*}}\vspace{.5em}}}

\newlength{\freespace}
\newcommand{\chapterend}{\par
  \setlength{\freespace}{\dimexpr \pagegoal-\pagetotal}%
  \ifdim\freespace > \dimexpr\ht\asterism+\textfloatsep\relax
    \begin{figure}[b]\usebox\asterism\end{figure}%
  \fi}
    
\begin{document}
\large

\chapter*{CHAPTER 1.}
\thispagestyle{empty}
\lipsum[3]
\footnote{This is a test}
%\footnote{\lipsum[2]}
\chapterend

\chapter*{CHAPTER 2.}
\lipsum[3-4]
\chapterend
\end{document}
Related Question