2

I would like to have a different background image for each part (not each chapter). I managed to do it but it's the same image that comes up every time, how can I customize that?

Below is my code and the output.

\documentclass[oneside,11pt]{memoir} % Font size
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[osf]{libertine} % Use the Libertine font
\usepackage[osf]{libertine} % Use the Libertine font
\usepackage{tikz} % Required for drawing custom shapes
\usepackage{wallpaper} % Required for setting background images (title page)
\usepackage{xcolor}
\renewcommand{\partnamefont}{\tikz[remember picture,overlay] \node[inner sep=0pt] at (current page.center){\includegraphics[width=\paperwidth,height=\paperheight]{picA.jpg}};\color{white}\centering\sffamily\itshape\Huge} % Part name font specification
\renewcommand{\partnumfont}{\sffamily\Huge} % Part number font specification
\renewcommand{\parttitlefont}{\centering\sffamily\scshape} % Part title font specification
\renewcommand{\beforepartskip}{\null\vskip.618\textheight} % Whitespace above the part heading
\begin{document}
\part{Picture A}
\part{Picture B}
\end{document}

Output :

enter image description here enter image description here

And here the second picture I would like to insert in the second part :

enter image description here

1 Answer 1

2

This can be achieved with tikz-page and LaTeX3. Try the example below.

enter image description here

\documentclass[oneside,11pt]{memoir} % Font size
\usepackage[utf8]{inputenc} % Required for inputting international characters
\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[osf]{libertine} % Use the Libertine font
\usepackage[osf]{libertine} % Use the Libertine font
\usepackage{tikz} % Required for drawing custom shapes
\usepackage{tikz-page}
\usepackage{expl3}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage[export]{adjustbox}
\renewcommand{\partnamefont}{\color{blue}\centering\sffamily\itshape\Huge}
\renewcommand{\partnumfont}{\color{blue}\sffamily\Huge} % Part number font specification
\renewcommand{\parttitlefont}{\color{blue}\centering\sffamily\scshape} % Part title font specification
\renewcommand{\beforepartskip}{\null\vskip.618\textheight} % Whitespace above the part heading

\makeatletter
\ExplSyntaxOn

\tl_new:N \g_doc_part_page_tl

% modify the \part command to store the number of part page
\patchcmd{\part}{\@setuppart}{
  \@setuppart
  \tl_gset:Nx \g_doc_part_page_tl {\thepage}
}{}{\GenericError{}{unable to patch command}{}{}}


\newcommand{\tikzpagelayout}{
  \int_compare:nNnT {\thepage} = {\g_doc_part_page_tl} {
    \int_case:nnF {\c@part} { 
      {1} {% code for part 1
        \node at (page.center) {
          \includegraphics[width=\paperwidth, height=\paperheight]{example-image-a}  
        };
      }
      {2} {% code for part 2
        \node at (page.center) {
          \includegraphics[width=\paperwidth, height=\paperheight]{example-image-b}  
        };
      }
      % you may continue to define part 3, 4, ...
    }
    {
      % unknown part, use default (gray) background
      \node[
      minimum~width=\paperwidth,
      minimum~height=\paperheight,
      fill=gray!50
      ] at (page.center) {};  
    }
  }
}
\ExplSyntaxOff
\makeatother


\begin{document}
  \part{Picture A}
  \Blindtext[3]
  \part{Picture B}
  \Blindtext[3]
  \chapter{A chapter}
  \Blindtext[3]
  \part{Picture C}
  \Blindtext[3]
\end{document}
4
  • Hi @Alan, thank you for your answer. This is working, however if I add a \chapter line after \part I still have the picture on the background. Is it possible to make the background only for the \part pages and not \chapter ones ?
    – Red One
    Commented Jun 8, 2021 at 0:18
  • Modified the \part command to change the behavior.
    – Alan Xiang
    Commented Jun 8, 2021 at 0:41
  • thanks again for your answer. It did work now, I have the background only on the \part pages. I still have one problem, I'm having a strait line on the top of the part and chapter pages, but if I delete the \usepackage{tikz-page} command, the line disappear with the background. How can I delete the strait line without deleting the background ?
    – Red One
    Commented Jun 8, 2021 at 1:01
  • 1
    You can add \renewcommand{\headrulewidth}{0pt} to the preamble.
    – Alan Xiang
    Commented Jun 8, 2021 at 3:33

You must log in to answer this question.

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