LaTeX 不允许我添加两个背景图

LaTeX 不允许我添加两个背景图

我正在用 LaTeX 写一本书。我想在每个“Part_X”首页和每个“Chapter_X”首页后面放置一个填满页面的 .png 图片。每个部分和章节的填满页面的 .png 图片都不同。以下是它应该是什么样子的示例:

在此处输入图片描述

下面是一些简化的 LaTeX 代码,应将其放在'testFig_01.png'“Part_1”首页和'testFig_02.png'“Chapter_01”首页后面:

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{wallpaper}

% Book's title and subtitle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{
    \Huge \textbf{FreeRTOS} \\
    \huge The internal mechanisms explained}

% Author
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\author { 
    \textsc{Kristof Mulier}
    \thanks{\url{www.sirris.be}}
}

% I want to put the figure 'testFig_01.png' as
% the background of the Part I frontpage.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Source: http://tex.stackexchange.com/questions/94878/page-background-color-for-part
\usepackage{xpatch}
%
\xpatchcmd{\part}{\thispagestyle{plain}}
{\ThisCenterWallPaper{1}{./testFig_01}\thispagestyle{plain}}{}{}
\xpatchcmd{\@endpart}{\vfil\newpage}{\vfil\newpage
    \pagecolor{white}}{}{}


\begin{document}

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%                                                  %%
    %%                  FRONTMATTER                     %%
    %%                 -------------                    %%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \frontmatter %  Turns off chapter numbering
                 %  and uses roman numerals for
                 %  page numbers.

    \maketitle


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%                                                  %%
    %%                   MAINMATTER                     %%
    %%                  ------------                    %%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \mainmatter  %  Turns on chapter numbering,
                 %  resets page numbering and
                 %  uses arabic numerals for page numbers.


    %%%%%%%%%%%%%%%%
    %% CHAPTER_01 %%
    %%%%%%%%%%%%%%%%
    \part{My first part}

        % I want to put 'testFig_02.png' as the
        % background of the Chapter 1 frontpage
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        \chapter{Documentation overview}
        \ThisCenterWallPaper{1}{./testFig_02}

        \clearpage

            \section{Section heading}
            Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. \\ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \\ Lorem ipsum list:



    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%                                                  %%
    %%                   BACKMATTER                     %%
    %%                  ------------                    %%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \backmatter   %  Turns off chapter numbering and
    %  doesn't fiddle with page numbering.

    \chapter{Back}
    A word to say goodbye.


\end{document}

不幸的是,上面显示的 LaTeX 代码只将'testFig_01'“Part_1”放在了首页后面,而没有将'testFig_02'“Chapter_01”放在首页后面。奇怪的是,我注意到注释掉放在'testFig_01'“Part_01”后面的代码将允许'testFig_02'将其绘制在“Chapter_01”后面:

% COMMENTED OUT:
% I want to put the figure 'testFig_01.png' as
% the background of the Part I frontpage.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \usepackage{xpatch}
%
% \xpatchcmd{\part}{\thispagestyle{plain}}
% {\ThisCenterWallPaper{1}{./testFig_01}\thispagestyle{plain}}{}{}
% \xpatchcmd{\@endpart}{\vfil\newpage}{\vfil\newpage
%     \pagecolor{white}}{}{}

看起来 LaTeX 不允许我\ThisCenterWallPaper{..}多次使用该命令将背景图像放入文档中。我该怎么办?

答案1

删除修补的行\@endpart。您不需要不透明的白色页面颜色。然后,您就可以使用代码获得所需的结果。


这是另一个建议。在下面的例子中,所有部分页面都获得由设置的背景图像\setpartbackgroundimage{<image>}。要更改图像,请在之前使用此命令\part。要获取没有图像的部分页面,只需使用空参数。

如果章节页面需要获取背景图像,请使用\chapterbackgroundimage{<image>}after \chapter

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage{wallpaper}

\usepackage{xpatch}
\newcommand\partbackgroundimage{}
\newcommand\setpartbackgroundimage[1]{\renewcommand\partbackgroundimage{#1}}
    \xpatchcmd{\part}{\thispagestyle{plain}}
      {\ifdefempty{\partbackgroundimage}{}{\ThisCenterWallPaper{1}{\partbackgroundimage}}%
        \thispagestyle{plain}}{}{}

\newcommand\chapterbackgroundimage[1]{\ThisCenterWallPaper{1}{#1}\clearpage}

\title{Title}
\author{Author}

\usepackage{lipsum} % dummy text
\begin{document}
\frontmatter
\maketitle

\mainmatter
\setpartbackgroundimage{example-image-A}
\part{My first part}

\chapter{Documentation overview}
\chapterbackgroundimage{example-image-B}

\section{Section heading}
\lipsum

\backmatter
\chapter{Back}
A word to say goodbye.
\end{document}

相关内容