0

I'm making a template for a friend who's been writing a fiction book for years, struggling with his time commitment (family happens). My goal is to completely separate format from content (hence LaTeX), so he can focus on his story.

I wanted to add an image before a chapter. In the book class, new chapters start on odd pages. Would it be possible to add a full page image in the immediately preceding even page?

MWE

\documentclass[a5paper,demo]{book}
\usepackage{lipsum}
\usepackage{graphicx}
\title{Captain Awesome in the Awesome land}
\author{Eric Cartman}
\begin{document}
    \maketitle
    \frontmatter
    \tableofcontents
    \mainmatter
    \chapter{Awesome}
    \lipsum[1-2]
    
    \begin{figure}[p]
        \centering
        \includegraphics[width=\textwidth]{dummy.pdf}
    \end{figure}
    
    \chapter{More Awesome}
    \lipsum[1-2]
\end{document}

This adds a black square dummy placeholder image at the end of chapter 1, plus a white page so chapter 2 starts on the odd side of the book. I would like this placeholder image immediately before chapter 2.

BTW, in the template I'm putting the chapters on separate .tex files, and adding them into the book via a pattern expansion loop. That way my friend wouldn't even need to type \include{chap37} in the master document.

Thanks

EDIT: To clarify, the request is the page of placement for that image. I don't care if it's considered part of Chapter 1 or 2. I believe it needs to be part of Chapter 1, because Chapter 2 must begin in the heading, for TOC purposes. But in a book with 37 chapters, I might want to add some images in the preceding even page to some of those chapters, not to all of them. And it will definitely be a different image in each case. Something related to the story of that chapter. And some chapters will end in an odd page. Some will end on an even page.

EDIT 2: I found a partial solution. The chapter in question should have this instead of simply \chapter{}

\cleartoevenpage
\includegraphics{chapter pic}
\chapter{chapter title}

This is the behavior I wanted, needed. However, I'm also using \part. The clear page after the part page plus the clear page before the image puts two white pages after the part sheet, which is undesirable. In this case, the image should be placed on the page after the \part and before \chapter. The modified MWE:

\documentclass[a5paper,demo]{book}
\usepackage{lipsum}
\usepackage{graphicx}
\title{Captain Awesome in the Awesome land}
\author{Eric Cartman}
\begin{document}
    \maketitle
    \frontmatter
    \tableofcontents
    \mainmatter
    \part{Foo}
    \chapter{Awesome}
    \lipsum[1-2]
    \part{Bar}
    \cleartoevenpage
    \begin{figure}[p]
        \centering
        \includegraphics[width=\textwidth]{dummy.pdf}
    \end{figure}
    
    \chapter{More Awesome}
    \lipsum[1-2]
\end{document}
6
  • BTW, so far I tried the float package with option H, and the placeins package, putting \FloatBarrier in several places, without success.
    – phollox
    Commented Mar 6 at 17:34
  • An if the precending even page has text on it? Commented Mar 7 at 4:39
  • 1
    Somewhat related tex.stackexchange.com/questions/552180/… Commented Mar 7 at 4:52
  • If the preceding page (an even page) has text in it, then an empty page must be added (odd side), then the image in an even page, then new chapter on the odd page. The book class usually takes care of this
    – phollox
    Commented Mar 7 at 5:44
  • Are you sure that the book class is best for that? Existing alternatives are the standard memoir and the custom novel. I have another custom class (not public yet) that addresses the very question you asked, for exactly that reason. It does it by not automatically clearing to recto (upon request). Also depends whether the finished product is an Ebook or paper book. Presumably paper, or the question makes less sense.
    – user287367
    Commented Mar 12 at 1:18

1 Answer 1

0

You could adjust the \cleardoublepage definition. Replace the original empty \hbox{} on the even page with \noindent\includegraphics[width=\textwidth]{example-image}.

The original code of \cleardoublepage:

\def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else\hbox{}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}

The adjusted version of \cleardoublepage:

\def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else\noindent\includegraphics[width=\textwidth]{example-image}\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}

A full example (note: before contents there will be also a full page image, because contents is unnumbered chapter as well):

Edits: add a toggle in the code \ifaddimages, set it to true when want the image to be added or false when don't want to add. Define a new command \theaddimage expanded to the image name which will be added. Redefine this command to change the added images.

\documentclass[a5paper]{book}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{graphicx}
\title{Captain Awesome in the Awesome land}
\author{Eric Cartman}
\newif\ifaddimages\addimagestrue
\newcommand{\theaddimage}{example-image-a}
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside\ifodd\c@page\else\ifaddimages\vspace*{-\topskip}\vspace*{\fill}\noindent\includegraphics[width=\textwidth]{\theaddimage}\vspace{\fill}\else\hbox{}\fi\newpage\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\begin{document}
    \maketitle
    \frontmatter
    \tableofcontents
    \renewcommand{\theaddimage}{example-image-b}\addimagesfalse
    \mainmatter
    \chapter{Awesome}
    \addimagestrue
    \lipsum[1]
    \chapter{More Awesome}
    \lipsum[1-2]
    \chapter{More Awesome}
    \lipsum[1]
\end{document}

enter image description here enter image description here enter image description here

4
  • Thanks for your reply. I did not explain myself sufficiently. I wanted to add a single image in the even page before a specific chapter. I could want to add only one, or a different image before every chapter, or only before some of them. So your approach, although interesting and illuminating, does not satisfy my current needs
    – phollox
    Commented Mar 6 at 18:05
  • @phollox You could put some if statements in the code. Let me work on some examples.
    – Tom
    Commented Mar 6 at 18:10
  • Your answer gave me the idea of changing the definition of ``\chapter```, to add the image in the preceding page. Something like a chapter with two arguments: the title and the path to the image
    – phollox
    Commented Mar 6 at 18:14
  • @Yes, you can do that as well. See my edits in the answer.
    – Tom
    Commented Mar 6 at 18:20

You must log in to answer this question.

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