我正在尝试在目录页的背景中添加一个图形。类似于这个:
我找到了这个模板罗格朗橙皮书并尝试将那里使用的代码用于我的文档,但我仍然无法在我的应用程序中正确使用它。
这是我用来修改目录页面样式的代码(取自上面提到的模板,并做了一些修改)
\makeatletter
\renewcommand{\tableofcontents}{
\chapter*{
\vspace*{-50\p@}
\begin{tikzpicture}[remember picture, overlay]
\node[
anchor=north west,
inner sep=0pt,
] at (current page.north west) {\includegraphics[width=\paperwidth]{figure1.jpg}};
\draw[anchor=west] (current page.north west) node [
anchor=north west,
xshift=3cm,
yshift=-5cm,
line width=2pt,
rounded corners=10pt,
draw=blue,
fill=black!5,
fill opacity=0.6,
text opacity=1,
inner ysep=12.5pt,
inner xsep=20pt,
align=flush left,
text width=1.2\linewidth,
font=\huge\sffamily\bfseries,
] {};
\pgftext[right,x=6cm,y=0.2cm]{\color{blue}\Huge\scshape\bfseries\contentsname}
\end{tikzpicture}}
\@starttoc{toc}}
\makeatother
然而,当我在论文中运行它时,我得到的结果如下:
有趣的是,当我在 MWE 中使用相同的代码时,我得到了另一个结果:
以下是 MWE:
\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[sfdefault]{universalis}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\usepackage[linkcolor=black,colorlinks=true]{hyperref}
%% command to print the actual minitoc ---------------------------------------------
\newcommand{\printmyminitoc}{%
\begin{center}%
\begin{tikzpicture}%
\node[ anchor=south,
inner ysep=12.5pt, % Inner vertical padding
inner xsep=20pt, % Inner horizontal padding
align=flush left, % Text alignment inside box
](s) at (current page.south) {%
\begin{minipage}[c][][t]{0.90\textwidth}
\begin{flushright}
\renewcommand{\baselinestretch}{1.15}\selectfont
\startcontents[chapters]
\printcontents[chapters]{}{1}{}
\end{flushright}
\end{minipage}
};%
\draw[bottom color = blue!80, top color= blue!10, draw=blue!60,fill opacity=0.1,decorate, decoration={random steps,segment length=3pt,amplitude=1pt},line width=1.25pt] (s.north west) rectangle (s.south east);
\end{tikzpicture}%
\end{center}%
\vfill
\pagebreak
}
%% command to print the TOC ---------------------------------------------
\titlecontents{chapter}[0pc]
{\addvspace{0pt}}%
{\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=blue!60,draw=blue!60,rounded corners=5pt] (-2.8,-.2) rectangle (1,.7);%
\pgftext[left,x=-2.0cm,y=0.2cm]{\color{white}\Large\scshape\bfseries Chapter\ \thecontentslabel};%
\end{tikzpicture}\hspace{1.5cm}\color{blue!60}\large\scshape\bfseries}
{\color{blue!60}\large\scshape\bfseries}
{\color{blue!60}\;\dotfill\;\large\scshape\bfseries \thecontentspage}
% \titlerule
\titlecontents{section}[2.4pc]
{\addvspace{0.2pt}}
{\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\dotfill\small \thecontentspage}
[]
\titlecontents{subsection}[5pc]
{\addvspace{0.2pt}}
{\hspace{1.6cm}\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\dotfill\small\thecontentspage}
[]
\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-50\p@}%
\begin{tikzpicture}[remember picture, overlay]%
% Output the chapter image
\node[
anchor=north west, % Anchor point on the image
inner sep=0pt, % Inner padding
] at (current page.north west) {\includegraphics[width=\paperwidth]{figure1.jpg}};
% Box with the chapter title
\draw[anchor=west] (current page.north west) node [
anchor=north west, % Anchor point of the chapter box
xshift=3cm, % Horizontal distance from the left side of the page
yshift=-5cm, % Vertical distance from the top of the page
line width=2pt, % Border line thickness
rounded corners=10pt, % Rounded corners amount
draw=blue, % Border line color
fill=black!5, % Box background color
fill opacity=0.6, % Background transparency
text opacity=1, % Text transparency
inner ysep=12.5pt, % Inner vertical padding
inner xsep=20pt, % Inner horizontal padding
align=flush left, % Text alignment inside box
text width=1.2\linewidth, % Box width (wider than page to go off the right side)
font=\huge\sffamily\bfseries, % Font styling for chapter title
] {}; % Chapter title in a fixed width box for wrapping
\pgftext[right,x=6cm,y=0.2cm]{\color{blue}\Huge\scshape\bfseries\contentsname}
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
\begin{document}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\frontmatter
\pagenumbering{roman}
\pagestyle{empty}
\setcounter{tocdepth}{2}
\tableofcontents
\cleardoublepage
\mainmatter
\pagenumbering{arabic}
\setcounter{page}{1}
\pagestyle{headings}
\chapter{Intro}
\printmyminitoc
\lipsum[1-3]
\section{Intro 1 - Section 1}
\lipsum[1-3]
\section{Intro 1 - Section 2}
\lipsum[1-3]
\section{Intro 1 - Section 3}
\lipsum[1-3]
\section{Intro 1 - Section 4}
\lipsum[1-3]
\section{Intro 1 - Section 5}
\lipsum[1-3]
\chapter{Literature}
\printmyminitoc
\lipsum[1-3]
\section{Literature - Section 1}
\lipsum[1-3]
\section{Literature - Section 2}
\lipsum[1-3]
\section{Literature - Section 3}
\lipsum[1-3]
\section{Literature - Section 4}
\lipsum[1-3]
\section{Literature - Section 5}
\lipsum[1-3]
\end{document}
有人可以指导我如何实现这种定制吗?
答案1
这里很难帮到你,因为你的 MWE 输出结果与原始文件大不相同。因此,我删除了你的代码中的所有内容,只留下了 ToC 标题所需的内容,并专注于这一部分。
您需要将 放置\contentsname
在节点内部,而不是下面。不要使用\pgftext
,只需将普通宏放置在节点内部。此外,您已经为此节点定义了一些字体样式选项,因此我建议您将所有样式选项放在那里。
至于背景图片,为了防止太大而覆盖整个页面背景,我添加了一个宏。您可能需要通过更改为其他内容来\clip
调整图片的高度。yshift
tikzpicture
最后,由于您使用options将整个标题放在 中remember picture, overlay
,因此您需要调整目录标题与目录本身之间的间距,因为由于 options remember picture, overlay
,tikzpicture
没有高度。因此,如果您不添加任何垂直间距,标题可能会与目录条目重叠。
我希望这可以帮助你入门:
\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[sfdefault]{universalis}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\usepackage[linkcolor=black,colorlinks=true]{hyperref}
\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{3cm}%
\begin{tikzpicture}[remember picture, overlay]%
% Output the chapter image
\clip (current page.north west) rectangle ([yshift=-9cm]current page.north east);
\node[
anchor=north west, % Anchor point on the image
inner sep=0pt, % Inner padding
] at (current page.north west) {\includegraphics[width=\paperwidth]{example-image-a}};
% Box with the chapter title
\draw[anchor=west] (current page.north west) node [
anchor=north west, % Anchor point of the chapter box
xshift=3cm, % Horizontal distance from the left side of the page
yshift=-5cm, % Vertical distance from the top of the page
line width=2pt, % Border line thickness
rounded corners=10pt, % Rounded corners amount
draw=blue, % Border line color
fill=black!5, % Box background color
fill opacity=0.6, % Background transparency
text opacity=1, % Text transparency
inner ysep=12.5pt, % Inner vertical padding
inner xsep=20pt, % Inner horizontal padding
align=flush left, % Text alignment inside box
text width=1.2\linewidth, % Box width (wider than page to go off the right side)
font=\Huge\sffamily\scshape\bfseries\color{blue}, % Font styling for chapter title
] {%
\contentsname%
}; % Chapter title in a fixed width box for wrapping
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
\begin{document}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\frontmatter
\pagenumbering{roman}
\pagestyle{empty}
\setcounter{tocdepth}{2}
\tableofcontents
\newpage
\section{One}
\end{document}