我怎样才能赋予每个部分页面自己的背景图像?

我怎样才能赋予每个部分页面自己的背景图像?

我想为每个部分(而不是每个章节)设置不同的背景图片。我成功做到了,但每次出现的图片都一样,我该如何自定义呢?

下面是我的代码和输出。

\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}

输出 :

在此处输入图片描述 在此处输入图片描述

这是我想在第二部分插入的第二张图片:

在此处输入图片描述

答案1

这可以通过 LaTeX3 实现tikz-page。请尝试以下示例。

在此处输入图片描述

\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}

相关内容