1

I want to customize the links (appearance) in the TOC. In the entire document I use 'hidelinks' in hyperref (to turn of the box), and then have some fancy own link visualization (here for MWE replaced by dotuline).

So I changed the TOC Format to include hyperlinks. I turned on the "link boxes" for debugging and the result does not look good. For the number the click area is too short, and for label it goes wrong competely.

enter image description here MWE:

    \documentclass{book}
    \usepackage{titletoc}
    \usepackage{hyperref}
    \usepackage{ulem} 
    \titlecontents{chapter}[1pc]%
      {\addvspace{2ex}\Large\filright}%
      {\hyperlink{chapter.\thecontentslabel}{\dotuline{\thecontentslabel}}{1pc}}{\hspace*{-1pc}}%
      {\titlerule*[1pc]{.}\hyperlink{chapter.\thecontentslabel}{\dotuline{\contentspage}}}[]

    \begin{document}
    Link Customization: \hyperlink{chapter.1}{\dotuline{Jump to chapter 1}} 
    \tableofcontents
    \chapter{Dummy1}
    dummy
    \end{document}

Original TOC:

enter image description here

With:

    \titlecontents{chapter}[1pc]%
      {\addvspace{2ex}\Large\filright}%
      {\contentslabel[\thecontentslabel]{1pc}}{\hspace*{-1pc}}%
      {\titlerule*[1pc]{.}\contentspage}[]
1

This is an attempt to mimick the titletoc specified looks. However there is a bit of guess work for what titletoc uses for the right margin.

Package titlesec is loaded for using \titlerule command.

Links with \dotuline decoration from ulem are put in the Toc via etoc package.

\documentclass{book}
\usepackage{ulem} 
\usepackage{hyperref}

% Code from OP with titletoc
% \usepackage{titletoc}
% \titlecontents
%   {chapter}% section name
%   [1pc]% left margin
%   {\addvspace{2ex}\Large\filright}% above code
%   {\hyperlink{chapter.\thecontentslabel}%
%              {\dotuline{\thecontentslabel}}{1pc}}% numbered entry format
%   {\hspace*{-1pc}}% number-less entry format
%   {\titlerule*[1pc]{.}%
%    \hyperlink{chapter.\thecontentslabel}%
%              {\dotuline{\contentspage}}}% filler page format

\usepackage{titlesec}% to use \titlerule command
\usepackage{etoc}

\makeatletter % to use \@tocrmarg and \@pnumwidth from the LaTeX book class
\etocsetstyle 
        {chapter}
        {\Large\leftskip 1pc \rightskip \@tocrmarg \parfillskip -\rightskip }
        {\addvspace{2ex}}
        {\noindent
         \etocifnumbered
            {\llap{\makebox[1pc][l]{\etoclink{\dotuline{\etocthenumber}}}}}%
            {\hspace*{-1pc}}%
         \etoclink{\dotuline{\etocthename }} % <- I leave intentional \space
         \titlerule*[1pc]{.}%
         \nobreak
         \makebox[\@tocrmarg][r]
            {\etoclink{\dotuline{\makebox[\@pnumwidth][c]{\etocthepage}}}}%
         \par}
        {}
\makeatother

\begin{document}
% Link Customization: \hyperlink{chapter.2}{\dotuline{Jump to chapter 2}} 

\tableofcontents
\chapter{Dummy1}
dummy1


\chapter{Dummy2}
dummy2

\chapter*{Dummy3}
\addcontentsline{toc}{chapter}{Dummy3}
dummy3
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.