1

How can I make the part of the document clickable from table of contents in book class? Despite of the fact I was able to make the chapters and sections clickable (as You can see in the picture below), when it comes to say about parts, brought me a trouble...

My 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}

Current situation

  • I assume that hyperref is being loaded automatically by one of the other packages. In any cae, see https://tex.stackexchange.com/questions/372570/hyperlinks-and-page-breaks-in-a-cross-referenced-toc. I should warn you that loading tocloft makes other changes stop working. – John Kormylo Sep 25 '22 at 15:36
  • @JohnKormylo I will see it, thanks! – constantin_d Sep 25 '22 at 19:07

0 Answers0