![我怎样才能赋予每个部分页面自己的背景图像?](https://linux22.com/image/434925/%E6%88%91%E6%80%8E%E6%A0%B7%E6%89%8D%E8%83%BD%E8%B5%8B%E4%BA%88%E6%AF%8F%E4%B8%AA%E9%83%A8%E5%88%86%E9%A1%B5%E9%9D%A2%E8%87%AA%E5%B7%B1%E7%9A%84%E8%83%8C%E6%99%AF%E5%9B%BE%E5%83%8F%EF%BC%9F.png)
我想为每个部分(而不是每个章节)设置不同的背景图片。我成功做到了,但每次出现的图片都一样,我该如何自定义呢?
下面是我的代码和输出。
\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}