0

I add a background image to every page and want to add a different one based on the name of the current chapter. It would also be good to know how whether the preface and title pages before the chapters start need their own treatment.

I unsuccessfully tried:

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage{graphicx}%

\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{\chaptermark}}}%
%
\begin{document}%
\chapter{example-image}
x
\end{document}
4
  • Are your chapter names really going to be existing images?
    – Werner
    Jan 17 at 0:12
  • @Werner my idea is to just name my images after the chapter names.
    – Christian
    Jan 17 at 0:13
  • @Christian: That works. You could also adapt your approach by adding something like \setchapterimage{<image>} at the start of the \chapter...
    – Werner
    Jan 17 at 0:14

1 Answer 1

2

Well you can extend \chaptermark to store the name. If you need a different name for some chapters, simply redefine it after the chapter.

\documentclass{book}%
\usepackage[T1]{fontenc}%
\usepackage{graphicx}%

\AddToHook{shipout/background}{\put(0pt, -\paperheight) {\includegraphics[width =\paperwidth, height =\paperheight]{\mychaptername}}}%
%
\newcommand\mychaptername{}

\NewCommandCopy\orichaptermark\chaptermark
\renewcommand\chaptermark[1]{\orichaptermark{#1}\def\mychaptername{#1}}
\begin{document}%
\chapter{example-image}
x
\end{document}

You must log in to answer this question.

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