使文档的各部分在目录 (TOC) 中可点击

使文档的各部分在目录 (TOC) 中可点击

我怎样才能使part文档的目录可点击book?尽管我能够使章节和部分可点击(如下图所示),但说到部分内容时,却给我带来了麻烦……

我的 MWE:

\documentclass[12pt, a4paper]{book}

%\usepackage[utf8]{inputenc} - not in lualatex!
\usepackage[polish]{babel}
\usepackage{polski}
\usepackage{indentfirst}

\usepackage[margin={2.5cm,2.5cm,2.5cm,2.5cm}]{geometry}

\usepackage[nottoc]{tocbibind}
\usepackage{tocloft}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@part}{%
    \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%%
}{%
    \addtocontents{toc}{\bfseries\protect\centering\Large\thepart.\hspace{1em}#1\par}%
}{}{}
\makeatother
\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}
\usepackage{lipsum}

\makeatletter
\def\contentsline#1#2#3#4{%
    \begingroup
    \Hy@safe@activestrue
    \edef\x{\endgroup
        \def\noexpand\Hy@tocdestname{#4}%
    }\x
    \csname l@#1\endcsname{%
        %\hyper@linkstart{link}{\Hy@tocdestname}{#2}\hyper@linkend
        #2%
    }{%
        %\hyper@linkstart{link}{\Hy@tocdestname}{#3}\hyper@linkend
        #3%
    }%
}
\makeatother

\makeatletter
% Update ToC hyperlinks for Chapters
\patchcmd{\l@chapter}% <cmd>
{{\cftchapfont #1}}% <search>
{\hyper@linkstart{link}{\Hy@tocdestname}{}{\cftchapfont #1}}% <replace>
{}{}% <success><failure>
\patchcmd{\cftchapfillnum}{\par}{\hyper@linkend\par}{}{}
% Update ToC hyperlinks for Sections
\patchcmd{\l@section}% <cmd>
{{\cftsecfont #1}}% <search>
{\hyper@linkstart{link}{\Hy@tocdestname}{}{\cftsecfont #1}}% <replace>
{}{}% <success><failure>
\patchcmd{\cftsecfillnum}{\par}{\hyper@linkend\par}{}{}


%-| | - for parts - here doesn't work... perhaps...
%\patchcmd{\l@part}% <cmd>
%{{\cftpartfont #1}}% <search>
%{\hyper@linkstart{link}{\Hy@tocdestname}{}{\cftpartfont #1}}% <replace>
%{}{}% <success><failure>
%\patchcmd{\cftpartfillnum}{\par}{\hyper@linkend\par}{}{}

\makeatother

\renewcommand{\cftchapaftersnum}{.}
\renewcommand{\cftchappresnum}{\bfseries}
\renewcommand\cftsecpagefont{\bfseries\normalsize}
\renewcommand{\cftchapleader}{\normalfont\cftdotfill{\cftchapdotsep}}
\renewcommand\cftchappagefont{\bfseries\normalsize}
\setlength{\cftbeforechapskip}{0.05cm}
\setlength{\cftchapnumwidth}{1cm}
\renewcommand{\cftsecfont}{\normalfont\normalsize}
\renewcommand{\cftchapfont}{\normalfont\large}
\renewcommand{\cftpartfont}{\bfseries\Huge}

\makeatletter\@addtoreset{chapter}{part}\makeatother%
\renewcommand{\thesection}{\thechapter.\arabic{section}.}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@makechapterhead}% <cmd>
{\@chapapp\space\thechapter\par\nobreak\vskip 20\p@}% <search>
{\Huge\space}% <replace>
{}{}% <success><failure>
\makeatother

\begin{document}
    \tableofcontents
    \part{Część pierwsza}
    \chapter{Rozdział 1}
    \lipsum[1]
    \section{Sekcja 1}
    \lipsum[2]
    \chapter{Rozdział 2}
    \lipsum[2]
    \section{Sekcja 2}
    \lipsum[3]
    \chapter{Rozdział 3}
    \lipsum[3]
    \section{Sekcja 3}
    \lipsum[4]
    \addtocontents{toc}{\vspace{0.5\baselineskip}}
    \part{Część druga}
    \chapter{Rozdział 1}
    \lipsum[1]
    \chapter{Rozdział 2}
    \lipsum[2]
    \chapter{Rozdział 3}
    \lipsum[3]
    
    \bookmarksetup{startatroot}
\end{document}

现在的情况

相关内容