我正在使用一个模板,所有章节的样式都使用相同的图像。我想在每一章中都更改它,但我不知道该怎么做。模板使用 tikzpicture,代码如下:
% Numbered chapters (with minitoc)
\renewcommand{\@makechapterhead}[1]{
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{
\begin{tikzpicture}[remember picture,overlay]
% Background image
\node[anchor=north west,inner sep=0pt] at (0,0)
{\includegraphics[width=\paperwidth]{images/back_mat.png}};
% Chapter heading
\draw[anchor=west, inner sep=0pt] (1 cm,-1.5 cm) node
[black,
ultra thick,
fill=tsorange!10,
fill opacity=.6,
inner sep=10pt]
(0,0)
{\parbox[t][1.6cm][t]{\paperwidth}
{\huge\bfseries\sffamily\flushleft\thechapter. #1}};
% Chapter Contents
\draw[anchor=west,inner sep=0pt] (8.8cm,-7cm) node
[tssteelblue,
ultra thick,
fill=white,
fill opacity=.8,
draw=tssteelblue,
draw opacity=1,
line width=1.5pt,
rounded corners,
inner sep=0pt]
(0,0)
{\hspace{1cm}\parbox[t][7.1cm][t]{11cm}
{\vspace{-1cm}\huge\bfseries\sffamily\flushleft
\textcolor{black}{\sffamily\minitoc}}};
\end{tikzpicture}
};
\end{tikzpicture}
\vspace{7.5cm}
}
我想将这个黑色图像作为不同章节的背景,尝试了某种更新命令,但无法做到:
这是我的 MWE:
\documentclass{tstextbook}
\begin{document}
\renewcommand{\contentsname}{Sumário}
\tsbook{livro pré vestibular - matemática}
{Personal Vestibulares - 2020}
{Cover Designer}
{2020}
{xxxxx}{xxx--xx--xxxx--xx--x}{0.0}
{São Paulo}
%---------------------------------------------------------------------------
% Chapters
%---------------------------------------------------------------------------
\input{chapter1}
\input{chapter2}
\printindex
\end{document}
提前感谢任何帮助!
答案1
你走在正确的道路上。
在课堂上,tstextbook.cls
每个章节的背景图是固定的。为了根据章节号更改它,您需要做两件事:
(1)添加代码以更改类使用的命令,\@makechapterhead
如代码所示,其中原始行 {\includegraphics[width=\paperwidth]{background}};
更改为,
{\includegraphics[width=\paperwidth]{back-chap-\thechapter}};
因此现在使用的图像将取决于章节号。
或者自己编辑tstextbook.cls
文件并更改该单行。
(2)提供背景图像,将其命名为back-chap-1
,back-chap-2
(同时保留文件格式)等等,并将它们放在background-images
以您的工作目录命名的目录中。
我从mwe
包中选择了三幅图像(example-image-a、example-image-b 和 example-image-c)并按照 (2) 中的说明进行了重命名。
这是代码
\documentclass[12pt,a4paper]{tstextbook}
\makeatletter
% Numbered chapters (with minitoc)
\renewcommand{\@makechapterhead}[1]{
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{
\begin{tikzpicture}[remember picture,overlay]
% Background image
\node[anchor=north west,inner sep=0pt] at (0,0)
% {\includegraphics[width=\paperwidth]{background}};
{\includegraphics[width=\paperwidth]{./background-images/back-chap-\thechapter}}; %<<<<<<<<<<<<<<<<<<<<<<<< changed
% Chapter heading
\draw[anchor=west, inner sep=0pt] (-0.1cm,-1.5cm) node
[black,
ultra thick,
fill=tsorange!10,
fill opacity=.6,
inner sep=10pt]
(0,0)
{\parbox[t][1.6cm][t]{\paperwidth}
{\huge\bfseries\sffamily\flushleft\thechapter. #1}};
% Chapter contents
\draw[anchor=west,inner sep=0pt] (8.8cm,-7cm) node
[tssteelblue,
ultra thick,
fill=white,
fill opacity=.8,
draw=tssteelblue,
draw opacity=1,
line width=1.5pt,
rounded corners,
inner sep=0pt]
(0,0)
{\hspace{1cm}\parbox[t][7.1cm][t]{11cm}
{\vspace{-1cm}\huge\bfseries\sffamily\flushleft
\textcolor{black}{\sffamily\minitoc}}};
\end{tikzpicture}
};
\end{tikzpicture}
\vspace{7.5cm}
}
\makeatother
\begin{document}
\chapter{One}
\chapter{Two}
\chapter{Three}
\end{document}