(目录)图书目录的每一页都有多个不同的背景图片

(目录)图书目录的每一页都有多个不同的背景图片

OBJECTIVE:

能够在book目录的每一页上放置不同的背景图像。

WHAT HAS BEEN TRIED ALREADY:

1

\AddToShipoutPicture*{%
  \AtPageLowerLeft{%
   \put(.5\textwidth,.5\textheight) {\includegraphics[width=50mm,height=50mm,keepaspectratio]{example-image}}%
  }
}

有效,但目录第一页上只放置一张图片

2

\AddToHook{shipout/background}{%
\put(0mm,-240mm){\ifnum\value{page}=0 \includegraphics[width=200mm,height=250mm,keepaspectratio]{example-image}\fi}
}

不起作用,因为目录的页面被吞噬了,也就是没有编号,所以我无法将图像挂接到页码。

3

 \backgroundsetup{
scale=1,
color=black,
opacity=1,
angle=0,
position={47.27mm,-7mm}, 
contents={%
  \includegraphics[height=15ex,keepaspectratio]{example-image}
  }%
}  
\BgThispage

有效,但也只在目录第一页放置一张图片,

4

还发现这个帖子但它似乎将一张图片放在了目录的所有页面上。此外,我不想使用background包,因为我读到它已经过时了,并给了我Package everypage Warning,因此必须替换。
那么,我如何才能真正将不同的背景图像添加到目录的任何/一些/所有页面,考虑到它们会被吞噬,我宁愿避免使用background包?

请发现以下内容MWE很有用。不要介意它的笨拙,它只是为了示例而编译的。

% !TEX TS-program = LuaLaTeX
\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}

\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[
]

\usepackage{microtype}
\usepackage[shortcuts]{extdash} 
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage[
  paperwidth=6.125in,
  paperheight=9.25in,
  inner=0.625in,
  top=15mm,
  outer=20mm,
  bottom=24mm, 
  heightrounded 
]{geometry} 

\setlength{\parskip}{0ex}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

\usepackage{eso-pic}

\usepackage{fancyhdr}
\fancyhf{} 
\renewcommand{\headrulewidth}{0ex} 
\fancyfoot[LE,RO]{\thepage} 
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0ex}%
  \fancyhf[lef,rof]{\thepage}%
}

\usepackage{titlesec}
\titleclass{\part}{top}
\titleformat{\part}{\vfil\penalty500\vfilneg\centering\normalfont\LARGE}{\thepart.}{8ex}{\LARGE\centering}
\titlespacing*{\part}{0ex}{0ex plus 4ex minus 1ex}{-4ex} 
\titleclass{\chapter}{straight}
\titleformat{\chapter}{\vfil\penalty500\vfilneg\centering\normalfont\large}{\thechapter.}{8ex}{\large\centering}
\titlespacing*{\chapter} {0ex}{4ex plus 4ex minus 1ex}{-2ex} 

\usepackage{tocloft}
\addto\captionsrussian{%
  \renewcommand{\contentsname}{\normalfont\Large\textcolor{Black}{TOC}}%
}
\addtocontents{toc}{\cftpagenumbersoff{part}} 
\setlength{\cftbeforetoctitleskip}{0ex}
\setlength{\cftaftertoctitleskip}{17ex}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftpartfont}{\large}
\renewcommand{\cftchapfont}{\normalsize}
\renewcommand{\cftpartpagefont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand\cftchapleader{\cftdotfill{1}} 
\cftsetindents{part}{5.5em}{0em} \cftsetindents{chapter}{1em}{2em}
\renewcommand{\cftchapdotsep}{\cftdotsep}

\begin{document}

\frontmatter
\pagestyle{empty}
\setcounter{page}{0}

 
\begin{titlepage}
  \centering
  \fontsize{20ex}{20ex}\selectfont\bfseries\textcolor{Black} {TITLE PAGE}\par
\end{titlepage}
\clearpage

\baselineskip=12.5pt
\mainmatter

\pagestyle{plain}
\part[PART 1.]{\textcolor{Black}{PART 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 

\part[PART 2.]{\textcolor{Black}{PART 2}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\clearpage
 \AddToShipoutPicture*{%
  \AtPageLowerLeft{%
   \put(.5\textwidth,.5\textheight) {\includegraphics[width=50mm,height=50mm,keepaspectratio]{example-image}}%
  }
}

\pagenumbering{gobble}   
  \tableofcontents

  \end{document}

答案1

包裹参考值为 LaTeX 提供了增强的交叉引用机制。

您可以使用该包参考值用于存储和检索 zref-label 中目录开始页面的所谓“绝对页码”的值。
在下面的示例中,该 zref-label 称为“toc-start”。

此外,您还可以定义一个宏\CodeForBackgroundOfAbsolutePage,在其中指定绝对页码和一些代码,以便将指令附加到钩子“shipout/background”中,以便仅在绝对页码具有指定值的页面的背景图片环境中执行代码。

在下面的例子中,可以通过让 TeX 执行涉及访问 zref 标签的计算来指定绝对页码。即 zref 标签“toc-start”。因此,在下面的例子中,\CodeForBackgroundOfAbsolutePage不仅需要两个参数(绝对页码和代码),还需要三个参数,其中一个表示逗号分隔的 zref 标签列表,必须定义这些列表才能计算出绝对页码的规范。如果其中一个 zref 标签未定义,就像第一次编译中的情况一样,代码也不会执行。

因此语法\CodeForBackgroundOfAbsolutePage是:

\CodeForBackgroundOfAbsolutePage
  {<comma-list of zref-labels that must exist for the code to be carried out>%
    % Here you specify both those zref-labels that are needed for the
    % <expression for computing the absolute page number of the page where code
    % shall be carried out> to work out and probably also those zref-labels that
    % are needed for the <code to execute in the page's background-picture-
    % environment> to work out.
  }%
  {<expression for computing the absolute page number of the page where code 
    shall be carried out>}%
  {<code to carry out within the specified page's background-picture-
    environment>}%

该命令\CodeForBackgroundOfAbsolutePage仅在 TeX 遇到该命令时要排版的页面尚未排版的情况下才有效。因此我建议在之前使用它\begin{document}
其他东西也可能添加到钩子“shipout/background”中。添加东西的顺序很重要,因为这会影响未绘制在上方/下方/左侧/右侧但彼此重叠的东西的重叠方式。

在以下示例中,zref 用于放置某种交叉引用标签。
在以下示例中,这是通过向保存目录数据的 .toc 文件添加放置 zref 标签“toc-start”的指令来实现的。
在第一次 latex 运行中,保存目录数据的 .toc 文件尚不存在。
该命令\tableofcontents位于文档末尾。因此,在第二次运行中,.toc 文件在 LaTeX 运行结束时进行处理,因此该文件中创建交叉引用标签/创建 zref 标签的指令在第二次 latex 运行结束时执行。
这反过来意味着这些交叉引用标签/zref 标签在第二次 latex 运行结束之前未定义/不可用。
这反过来意味着该文档需要至少编译三次才能确保所有内容正确匹配。
无论如何,请遵守控制台和 .log 文件中有关需要重新运行 LaTeX 的消息和警告。

事情可能会更加精确,并且您可能只需要编译文档两次而不是三次,通过不添加将 zref 标签“toc-start”放置在 .toc 文件中的指令,而是修补命令\tableofcontents以在目录的第一个单词或行排版后立即执行该指令 - 这可能是目录的标题。

% !TEX TS-program = LuaLaTeX
%===============================================================================
\makeatletter
\RequirePackage[abspage]{zref}
\ExplSyntaxOn
%...............................................................................
% Save the  value of abspage-counter to a zref-label:
%...............................................................................
\cs_new_protected:Npn \saveabspage #1 {\zref@labelbyprops{#1}{abspage}}
%...............................................................................
% Obtain the saved abspage-counter-value from zref-label if possible, otherwise
% deliver -1:
%...............................................................................
\cs_new_protected:Npn \getabspage #1 {\zref@extractdefault{#1}{abspage}{-1}}
%...............................................................................
% Map over comma-list #1 denoting zref-labels and execute code #2 in case all of
% them are defined, otherwise execute code #3; this is for doing calculations 
% with zref-labels which can only be done in case all of them are defined:
%...............................................................................
\cs_new:Npn \CheckWhetherAllZlabelsDefined #1 
  {
    \exp:w
      \clist_map_function:nN {#1} \mystuff_checkzlabel:nwnn
      \exp_after:wN\exp_end:\use_i:nn
  }
\cs_new:Npn \mystuff_checkzlabel:nwnn #1#2 \exp_after:wN\exp_end:\use_i:nn #3#4
  {
    \int_compare:nNnTF {\getabspage{#1}}={-1}
      {#2 \exp_after:wN\exp_end:\use_i:nn {#4}}
      {#2 \exp_after:wN\exp_end:\use_i:nn {#3}}{#4}%
  }
%...............................................................................
% Map over comma-list denoting zref-labels and generate warning for each 
% undefined zref-label:
%...............................................................................
\cs_new_protected:Npn \WarnForUndefinedZlabels #1
  {
    \clist_map_function:nN {#1}\zref@refused
  }
%...............................................................................
% Provide code to execute on background-picture-environment of page whose
% absolute page number is to be specified:
%...............................................................................
\cs_new_protected:Npn \CodeForBackgroundOfAbsolutePage#1#2#3{ 
  % #1 = comma-list of zref-labels that must exist for the code (#3) to be 
  %      carried out.
  % #2 = expression for computing the absolute page number of the page within
  %      whose background-picture-environment code (#3) shall be carried out:
  % #3 = code to carry out within the specified page's background-picture-
  %      environment
  \AddToHook{shipout/background}{
    \WarnForUndefinedZlabels{#1}
    \int_compare:nNnT {\CheckWhetherAllZlabelsDefined{#1}{#2}{-1}}
                      =
                      {\value{abspage}}
                      {#3}
  }
}
\ExplSyntaxOff
%...............................................................................
% Add a zref-label denoting the absolute page number of the first page of the 
% table of contents:
%   Depending on preface delivered by the \tableofcontents-command the following
%   might not be exact so that instead of adding to the .toc-file you might
%   need to patch the command \tableofcontents to place the zref-label
%   "toc-start" right after the heading of the table of contents.
%...............................................................................
\AtBeginDocument{\addtocontents{toc}{\saveabspage{toc-start}}}%
\makeatother
%===============================================================================

\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}

\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[]

\usepackage{microtype}
\usepackage[shortcuts]{extdash} 
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage[
  paperwidth=6.125in,
  paperheight=9.25in,
  inner=0.625in,
  top=15mm,
  outer=20mm,
  bottom=24mm, 
  heightrounded 
]{geometry} 

\setlength{\parskip}{0ex} % Better use a package for this kind of things which
                          % takes subtleties into account.
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

\usepackage{fancyhdr}
\fancyhf{} 
\renewcommand{\headrulewidth}{0ex} 
\fancyfoot[LE,RO]{\thepage} 
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0ex}%
  \fancyhf[lef,rof]{\thepage}%
}

\usepackage{titlesec}
\titleclass{\part}{top}
\titleformat{\part}{\vfil\penalty500\vfilneg\centering\normalfont\LARGE}%
            {\thepart.}{8ex}{\LARGE\centering}
\titlespacing*{\part}{0ex}{0ex plus 4ex minus 1ex}{-4ex} 
\titleclass{\chapter}{straight}
\titleformat{\chapter}{\vfil\penalty500\vfilneg\centering\normalfont\large}%
            {\thechapter.}{8ex}{\large\centering}
\titlespacing*{\chapter} {0ex}{4ex plus 4ex minus 1ex}{-2ex} 

\usepackage{tocloft}
%...............................................................................
% Probably it is nice to be informed about changes in auxiliary files:
\usepackage[starttoc]{rerunfilecheck}
%...............................................................................
\addto\captionsrussian{%
  \renewcommand{\contentsname}{\normalfont\Large\textcolor{Black}{TOC}}%
}
\addtocontents{toc}{\cftpagenumbersoff{part}} 
\setlength{\cftbeforetoctitleskip}{0ex}
\setlength{\cftaftertoctitleskip}{17ex}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftpartfont}{\large}
\renewcommand{\cftchapfont}{\normalsize}
\renewcommand{\cftpartpagefont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand\cftchapleader{\cftdotfill{1}} 
\cftsetindents{part}{5.5em}{0em} \cftsetindents{chapter}{1em}{2em}
\renewcommand{\cftchapdotsep}{\cftdotsep}

%...............................................................................
% Add code for the first page of the table of contents; in the argument for
% computing the number of the absolute page where code shall be carried out use 
% \getabspage{toc-start} for obtaining the value of the absolute page-number of
% the first page of the table of contents:
%...............................................................................
\CodeForBackgroundOfAbsolutePage{%
  % The zref-label "toc-start" must exist for the expression for computing the
  % number of the absolute page where code shall be carried out to work out, so
  % it is the only element of the comma-list of zref-labels that must exist for
  % the cod to be carried out.:
  toc-start
}{%
  % Expression for computing the number of the absolute page where code shall 
  % be carried out.
  \getabspage{toc-start}%
}{% Code to carry out inside the background-picture-environment of the 1st page
  % of the table of contents.
  % Be aware that the picture's origin (0,0) is the top left corner of the page
  % and that the first argument of `\put` denotes how far to go to the right and
  % _upwards_ in relation to the origin.
  % So upwards-direction needs to be specified _negative_ as otherwise things
  % end up above the topmargin of the page.
  \put(0, 0) {%
    \vtop to \paperheight{% \paperheight is how far the \vtop goes downwards
                          % from the baseline of the topmost horizontal box/item 
                          % inside the \vtop. The baseline of the topmost 
                          % horizontal box/item inside the \vtop is also the
                          % baseline of the \vtop-box itself.
                          % The baseline of the \vtop-box is vertically aligned
                          % with the coordinate (0,0). 
      \hsize=\paperwidth % \hsize is the width of lines in case TeX switches to
                         % horizontal mode for doing line breaking
                         % automatically.
                         % In so-called *restricted* horizontal mode, e.g., 
                         % when carrying out a \hbox-command, TeX does not do
                         % line-breaking.
      %.........................................................................
      % Use a \hrule of no height and no depth as topmost horizontal item of the
      % \vtop to make sure the \vtop's height is 0 - the \hrule will be the
      % baseline of the \vtop-box. The baseline of the \vtop-box is vertically
      % aligned with the coordinate (0,0). 
      % That coordinate denotes the top left corner of the page :
      %.........................................................................
      \hrule height 0pt width 0pt
      %.........................................................................
      \vfill
      \hbox to \paperwidth{%
        \hfill
        \hbox{%
          \includegraphics[width=.5\paperwidth]{example-image-a}%
        }%
        \hfill\null
      }%
      \vfill
    }%
  }%
}%
%...............................................................................
% Add code for the third page of the table of contents:
%...............................................................................
\CodeForBackgroundOfAbsolutePage{%
  % The zref-label "toc-start" must exist for the expression for computing the
  % number of the absolute page where code shall be carried out to work out, so
  % it is the only element of the comma-list of zref-labels that must exist for
  % the cod to be carried out.:
  toc-start
}{%
  % Expression for computing the number of the absolute page where code shall 
  % be carried out.
  \getabspage{toc-start}+2%
}{% Code to carry out inside the background-picture-environment of the 3rd page
  % of the table of contents.
  % Be aware that the picture's origin (0,0) is the top left corner of the page
  % and that the first argument of `\put` denotes how far to go to the right and
  % _upwards_ in relation to the origin.
  % So upwards-direction needs to be specified _negative_ as otherwise things
  % end up above the topmargin of the page.
  \put(0,-\paperheight) {%
    \vbox to \paperheight{% \paperheight is how far the \vbox goes upwards from
                          % the baseline of the last horizontal box/item at the
                          % bottom inside the \vbox. The baseline of the last
                          % horizontal box/item inside the \vbox at the bottom
                          % of the \vbox is also the baseline of the \vbox
                          % itself.
                          % The baseline of the \vbox-box is vertically aligned
                          % with the coordinate (0,-\paperheight). 
      \hsize=\paperwidth % \hsize is the width of lines in case TeX switches to
                         % horizontal mode for doing line breaking
                         % automatically.
                         % In so-called *restricted* horizontal mode, e.g., 
                         % when carrying out a \hbox-command, TeX does not do
                         % line-breaking.
      \vfill
      \hbox to \paperwidth{%
        \hfill
        \hbox{%
          \includegraphics[width=.5\paperwidth, height=.5\paperwidth, origin=c, 
                           angle=45]{example-image-b}%
        }%
        \hfill\null
      }%
      \vfill
      %.........................................................................
      % Use a \hrule of no height and no depth as the last horizontal item at
      % the bottom the \vbox to make sure the \vbox's depth is 0 - that \hrule
      % will be the baseline of the \vbox. The baseline of the \vbox is
      % vertically aligned with the coordinate (0,-\textheight). 
      % That coordinate denotes the bottom left corner of the page :
      %.........................................................................
      \hrule height 0pt width 0pt
    }%
  }%
}%
%...............................................................................

\begin{document}

\frontmatter

\pagestyle{empty}
%%%%%%%\setcounter{page}{0}

\begin{titlepage}
  \centering
  \fontsize{20ex}{20ex}\selectfont\bfseries\textcolor{Black} {TITLE PAGE}\par
\end{titlepage}

\clearpage

\baselineskip=12.5pt % <- Better use a package for this kind of things which 
                     %    takes subtleties into account.

\mainmatter
\pagestyle{plain}

% In a loop create sections so that the table of contents gets enough pages:

\def\scratch{0}%
\loop\ifnum\scratch<168 %
  \edef\scratch{\the\numexpr\scratch+1\relax}%
  \section{section \scratch} text
\repeat

\newpage
\pagenumbering{gobble}   
\tableofcontents

\end{document}

在此处输入图片描述

答案2

在这里使用\pagestyle{gobble}不是问题,因为它仍然会增加计数器page,只是\thepage会导致始终相同的空字符串:

% !TEX TS-program = LuaLaTeX
\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}

\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[]

\usepackage{microtype}
\usepackage[shortcuts]{extdash} 
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage[
  paperwidth=6.125in,
  paperheight=9.25in,
  inner=0.625in,
  top=15mm,
  outer=20mm,
  bottom=24mm, 
  heightrounded 
]{geometry} 

\setlength{\parskip}{0ex}% Not the best idea, better use package parskip.
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

\usepackage{eso-pic}

\usepackage{fancyhdr}
\fancyhf{} 
\renewcommand{\headrulewidth}{0ex} 
\fancyfoot[LE,RO]{\thepage} 
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0ex}%
  \fancyhf[lef,rof]{\thepage}%
}

\usepackage{titlesec}
\titleclass{\part}{top}
\titleformat{\part}{\vfil\penalty500\vfilneg\centering\normalfont\LARGE}{\thepart.}{8ex}{\LARGE\centering}
\titlespacing*{\part}{0ex}{0ex plus 4ex minus 1ex}{-4ex} 
\titleclass{\chapter}{straight}
\titleformat{\chapter}{\vfil\penalty500\vfilneg\centering\normalfont\large}{\thechapter.}{8ex}{\large\centering}
\titlespacing*{\chapter} {0ex}{4ex plus 4ex minus 1ex}{-2ex} 

\usepackage{tocloft}
\addto\captionsrussian{%
  \renewcommand{\contentsname}{\normalfont\Large\textcolor{Black}{TOC}}%
}
\addtocontents{toc}{\cftpagenumbersoff{part}} 
\setlength{\cftbeforetoctitleskip}{0ex}
\setlength{\cftaftertoctitleskip}{17ex}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftpartfont}{\large}
\renewcommand{\cftchapfont}{\normalsize}
\renewcommand{\cftpartpagefont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand\cftchapleader{\cftdotfill{1}} 
\cftsetindents{part}{5.5em}{0em} \cftsetindents{chapter}{1em}{2em}
\renewcommand{\cftchapdotsep}{\cftdotsep}

\begin{document}

\frontmatter
\pagestyle{empty}
\setcounter{page}{0}

 
\begin{titlepage}
  \centering
  \fontsize{20ex}{20ex}\selectfont\bfseries\textcolor{Black} {TITLE PAGE}\par
\end{titlepage}
\clearpage

\baselineskip=12.5pt
\mainmatter

\pagestyle{plain}
\part[PART 1.]{\textcolor{Black}{PART 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 

\part[PART 2.]{\textcolor{Black}{PART 2}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\clearpage
 \AddToShipoutPicture{%
  \AtTextLowerLeft{%
   \includegraphics[page=\value{page},width=\textwidth,height=\textheight,keepaspectratio]{example-image-a4-numbered}%
  }
}

\pagenumbering{gobble}   
  \tableofcontents
\clearpage
\ClearShipoutPictureBG% If more pages without images follow, it makes sense, to remove the background shipout code.

  \end{document}

通过选项页选择页面的示例

您也可以这样做\ifnum \value{page}=…。以下示例使用它,根据页码将不同的文件放置在不同的位置:

% !TEX TS-program = LuaLaTeX
\documentclass[11pt,twoside,openany]{book}
\pagestyle{plain}

\usepackage[english, russian]{babel}
\usepackage{fontspec}
\setmainfont{EB Garamond}[]

\usepackage{microtype}
\usepackage[shortcuts]{extdash} 
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage[
  paperwidth=6.125in,
  paperheight=9.25in,
  inner=0.625in,
  top=15mm,
  outer=20mm,
  bottom=24mm, 
  heightrounded 
]{geometry} 

\setlength{\parskip}{0ex}% Not the best idea, better use package parskip.
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}

\usepackage{eso-pic}

\usepackage{fancyhdr}
\fancyhf{} 
\renewcommand{\headrulewidth}{0ex} 
\fancyfoot[LE,RO]{\thepage} 
\pagestyle{fancy}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0ex}%
  \fancyhf[lef,rof]{\thepage}%
}

\usepackage{titlesec}
\titleclass{\part}{top}
\titleformat{\part}{\vfil\penalty500\vfilneg\centering\normalfont\LARGE}{\thepart.}{8ex}{\LARGE\centering}
\titlespacing*{\part}{0ex}{0ex plus 4ex minus 1ex}{-4ex} 
\titleclass{\chapter}{straight}
\titleformat{\chapter}{\vfil\penalty500\vfilneg\centering\normalfont\large}{\thechapter.}{8ex}{\large\centering}
\titlespacing*{\chapter} {0ex}{4ex plus 4ex minus 1ex}{-2ex} 

\usepackage{tocloft}
\addto\captionsrussian{%
  \renewcommand{\contentsname}{\normalfont\Large\textcolor{Black}{TOC}}%
}
\addtocontents{toc}{\cftpagenumbersoff{part}} 
\setlength{\cftbeforetoctitleskip}{0ex}
\setlength{\cftaftertoctitleskip}{17ex}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}
\renewcommand{\cftpartfont}{\large}
\renewcommand{\cftchapfont}{\normalsize}
\renewcommand{\cftpartpagefont}{\normalfont}
\renewcommand{\cftchappagefont}{\normalfont}
\renewcommand\cftchapleader{\cftdotfill{1}} 
\cftsetindents{part}{5.5em}{0em} \cftsetindents{chapter}{1em}{2em}
\renewcommand{\cftchapdotsep}{\cftdotsep}

\begin{document}

\frontmatter
\pagestyle{empty}
\setcounter{page}{0}

 
\begin{titlepage}
  \centering
  \fontsize{20ex}{20ex}\selectfont\bfseries\textcolor{Black} {TITLE PAGE}\par
\end{titlepage}
\clearpage

\baselineskip=12.5pt
\mainmatter

\pagestyle{plain}
\part[PART 1.]{\textcolor{Black}{PART 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 

\part[PART 2.]{\textcolor{Black}{PART 2}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\chapter[CHAPTER 1.]{\textcolor{Black}{CHAPTER 1}} 
\clearpage
\AddToShipoutPicture{%
  \ifnum \value{page}=1  
    \AtTextLowerLeft{%
      \includegraphics[page=1,width=.5\textwidth,height=.5\textheight,keepaspectratio]{example-image-a}%
    }%
  \fi
  \ifnum \value{page}=2  
    \AtTextCenter{%
      \includegraphics[page=1,width=.5\textwidth,height=.5\textheight,keepaspectratio]{example-image-b}%
    }%
  \fi
  \ifnum \value{page}=3  
    \AtTextUpperLeft{%
      \makebox(0,0)[lt]{\includegraphics[page=1,width=.5\textwidth,height=.5\textheight,keepaspectratio]{example-image-c}}%
    }%
  \fi
}

\pagenumbering{gobble}   
\tableofcontents
\clearpage
\ClearShipoutPictureBG% If more pages without images follow, it makes sense, to remove the background shipout code.

\end{document}

不同页面位置上有不同文件的示例

类似地,您可以加载名称取决于页码的文件,例如使用example-image-\alph{page}(但不要使用!)或类似名称。您可以测试这一点,将上例中的\thepage三个文件名example-image-aexample-image-b和替换为。example-image-cexample-image-\alph{page}

注意:如果您\setcounter{page}{0}在当前页面上有,那么此页面就\value{page}=0没有\value{page}=1

一个绝对简单的建议是,将相应的\AddToShipoutPicture*命令写入toc文件。为此,您只需查看目录,查看哪个章节或部分或小节位于目录的哪一页,然后\addtocontents{toc}{…}在文档中的相应位置添加代码,例如:

\documentclass[11pt,openany]{book}
\pagestyle{plain}
\usepackage{eso-pic}
\usepackage{mwe}

\begin{document}

\addtocontents{toc}{% inside the TOC
  \protect\AddToShipoutPicture*{% add it only to the next current page
    \protect\put(5cm,8cm){%
      \protect\includegraphics[page=1,width=.5\textwidth,height=.5\textheight,keepaspectratio]{example-image-a}%
    }%
  }%
}%    
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\addtocontents{toc}{% inside the TOC
  \protect\AddToShipoutPicture*{% add it only to the next current page
    \protect\put(5cm,12cm){%
      \protect\includegraphics[page=1,width=.5\textwidth,height=.5\textheight,keepaspectratio,angle=45]{example-image-b}%
    }%
  }%
}%    
\blinddocument
\blinddocument
\blinddocument
\blinddocument
\addtocontents{toc}{% inside the TOC
  \protect\AddToShipoutPicture*{% add it only to the next current page
    \protect\put(8cm,24cm){%
      \protect\includegraphics[page=1,width=.5\textwidth,height=.5\textheight,keepaspectratio,angle=180]{example-image-c}%
    }%
  }%
}%    
\blinddocument

\pagenumbering{gobble}   
\tableofcontents

\end{document}

得到下面的目录:

最微不足道的建议的结果

但是,这只有在目录最终确定时才有意义。如果您添加或删除章节、节或小节,则可能必须移动命令\addtocontents,以将背景图像添加到正确的页面。

如您所见,有很多可能性,可以添加或多或少相同的代码来将不同的图像加载到不同页面的背景中,或者向某些页面添加单独的代码。并且狼吞虎咽页码不是取消资格的因素,因为page计数器仍然存在并且每页仍在增加。

相关内容