精美章节页面中的链接

精美章节页面中的链接

这是 Gonzalo Medina 先生几年前编写的代码。我想知道如何将章节和节的链接添加到目录中。谢谢。

\documentclass{book}
\usepackage[margin=1.5cm,a5paper]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}
\usepackage{tikz}
\usepackage{epigraph}
\usepackage{xpatch}
\usepackage{lmodern}
\usepackage{lipsum}

\newlength\ChapWd
\settowidth\ChapWd{\huge\chaptertitlename}

\definecolor{myblue}{RGB}{0,0,122}

\titleformat{\chapter}[display]
  {\normalfont\filcenter\sffamily}
  {\tikz[remember picture,overlay]
    {
    \node[fill=myblue,font=\fontsize{60}{72}\selectfont\color{white},anchor=north east,minimum size=\ChapWd] 
      at ([xshift=-15pt,yshift=-15pt]current page.north east) 
      (numb) {\thechapter};
    \node[rotate=90,anchor=south,inner sep=0pt,font=\huge] at (numb.west) {\chaptertitlename};
    }
  }{0pt}{\fontsize{33}{40}\selectfont\color{myblue}#1}[\vskip10pt\Large***]
\titlespacing*{\chapter}
  {0pt}{50pt}{10pt}


\makeatletter
\xpatchcmd{\ttl@printlist}{\endgroup}{{\noindent\color{myblue}\rule{\textwidth}{1.5pt}}\vskip30pt\endgroup}{}{}
\makeatother

\newcommand\DoPToC{%
\startcontents[chapters]
\printcontents[chapters]{}{1}{\noindent{\color{myblue}\rule{\textwidth}{1.5pt}}\par\medskip}%
}

\setlength\epigraphrule{0pt}
\renewcommand\textflush{flushright}
\renewcommand\epigraphsize{\normalsize\itshape}

\begin{document}

\chapter{Title of the first chapter}
\epigraph{A brainy quote -- Its Author}{}
\DoPToC
\lipsum[4]
\section{A test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\section{Another test section}
\lipsum[4]
\section{Yet another test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]

\chapter{Title of the second chapter}
\DoPToC
\lipsum[4]
\section{A test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\section{Another test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]

\end{document}

答案1

我只需输入以下内容即可解决该问题

\usepackage{hyperref, bookmark}
\hypersetup{colorlinks=true,linkcolor=black,pdfborder={0 0 0}}

在序言中;以及,

\pdfbookmark[section]{\contentsname}{toc}

在该TOC线之前。

相关内容