我正在使用代码来tikz
制作精美的目录,我想使用包hyperref
和相关命令对其应用某些设置hyperrefsetup
。我想创建以下图像
或者至少是一些平滑的东西,例如章节编号应该与其标题和页码具有相同的颜色,而章节标题应该具有浅蓝色。
当我使用linkcolor
选项(我实际上需要它来获得彩色链接)时,似乎出现了混乱,其中所有目录条目都具有相同的颜色,而章节/章节/页面编号的颜色则不同,如下所示
或者
我如何获得第一张图像以及如何明确更改章节/页码颜色?
我的代码如下
\documentclass{book}
\usepackage{tikz}
%~~~~~~~~~~~~~~~~~~~~~Fancy ToC~~~~~~~~~~~~~~~~~~~~~~
\usepackage{titletoc}
\usepackage{titlesec}
\definecolor{doc}{RGB}{0,60,110}
\definecolor{myblueii}{RGB}{63,200,244}
\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=myblueii,draw=myblueii, rounded corners] (-4,-.1) rectangle (-0.15,.5);%
\pgftext[left,x=-2.7cm,y=0.2cm]{\color{white}\Large \chaptertitlename\ \thecontentslabel};%
\end{tikzpicture}\color{myblueii}\large\bfseries}%
{}
{}
{\hspace*{6pt}\titlerule\hspace*{6pt}\large\bfseries \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=myblueii, rounded corners=0pt] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents{subsection}[4.8pc]
{\addvspace{1.0pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small\thecontentspage}
[]
\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{myblueii}\Huge \contentsname};%
\draw[fill=myblueii,draw=myblueii, rounded corners=15pt] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge \contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
%~~~~~~~~~~~~~~~~~Hyperref Settings~~~~~~~~~~~~~~~~~~~~~~
\usepackage{hyperref}
\hypersetup{%
pdfborder = {0 0 0},
colorlinks,
citecolor=red,
filecolor=green,
linkcolor=myblueii,
urlcolor=cyan!50!black!90
}
%~~~~~~~~~~~~~~~~~Main Document~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
\tableofcontents
\chapter{rkbnjg}
\section{ljkihb;kjb}
\url{http://www.google.com}
\section{lkhb;hkb}
\section{;kjbkjb}
\subsection{;kjblkhjblhkb}
\subsection{lhjbljh}
\subsection{;jbnlkhjblbh}
\section{ljhblkhbj}
\subsection{ljhblhjkblkbh}
\chapter{kgjb}
\chapter{;kjdfb543}
\end{document}
答案1
正如评论中提到的,注释掉所有链接颜色后,您就会得到正确的结果。因此,在调用hidelinks
时局部使用该选项\tableofcontents
(灵感来自这)即写:
{
\hypersetup{hidelinks}
\tableofcontents%
}
完整的代码应该是:
\documentclass{book}
\usepackage{tikz}
\usepackage{titletoc}
\usepackage{titlesec}
\usepackage{hyperref}
%
\definecolor{doc}{RGB}{0,60,110}
\definecolor{myblueii}{RGB}{63,200,244}
%~~~~~~~~~~~~~~~~~Hyperref Settings~~~~~~~~~~~~~~~~~~~~~~
\hypersetup{%
pdfborder = {0 0 0},
colorlinks,
citecolor=red,
filecolor=green,
linkcolor=myblueii,
urlcolor=cyan!50!black!90
}
%~~~~~~~~~~~~~~~~~~~~~Fancy ToC~~~~~~~~~~~~~~~~~~~~~~
\contentsmargin{0cm}
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=myblueii,draw=myblueii, rounded corners] (-4,-.1) rectangle (-0.15,.5);%
\pgftext[left,x=-2.7cm,y=0.2cm]{\color{white}\Large \chaptertitlename\ \thecontentslabel};%
\end{tikzpicture}\color{myblueii}\large\bfseries}%
{}
{}
{\hspace*{6pt}\titlerule\hspace*{6pt}\large\bfseries \thecontentspage
\begin{tikzpicture}[remember picture, overlay]
\draw[fill=doc!25,draw=myblueii, rounded corners=0pt] (2pt,0) rectangle (6,0.1pt);
\end{tikzpicture}}%
\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
[]
\titlecontents{subsection}[4.8pc]
{\addvspace{1.0pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small\thecontentspage}
[]
\makeatletter
\renewcommand{\tableofcontents}{%
\chapter*{%
\vspace*{-20\p@}%
\begin{tikzpicture}[remember picture, overlay]%
\pgftext[right,x=15cm,y=0.2cm]{\color{myblueii}\Huge \contentsname};%
\draw[fill=myblueii,draw=myblueii, rounded corners=15pt] (13,-.75) rectangle (20,1);%
\clip (13,-.75) rectangle (20,1);
\pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge \contentsname};%
\end{tikzpicture}}%
\@starttoc{toc}}
\makeatother
%~~~~~~~~~~~~~~~~~Main Document~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
{
\hypersetup{hidelinks}
\tableofcontents%
}
\chapter{rkbnjg}
\section{ljkihb;kjb}
\url{http://www.google.com}
\section{lkhb;hkb}
\section{;kjbkjb}
\subsection{;kjblkhjblhkb}
\subsection{lhjbljh}
\subsection{;jbnlkhjblbh}
\section{ljhblkhbj}
\subsection{ljhblhjkblkbh}
\chapter{kgjb}
\chapter{;kjdfb543}
\end{document}
输出: