I solved most of my original problems so I am rewriting the question which is still fundamentally the same but now I can post a much nicer MWE.

The problem I am having is to make the dots in the table of contents into links that link to the relevant section/chapter. Essentially I want the clickable link to span from the text of the section all the way through to the page number, so that it includes the dots in between. I have tried a number of potential solutions but can't seem to get it to work.

Ultimately my goal is to mimic the example page given here, where I believe I have managed to do so except for some minor formating that I'm still finishing off (eg removing numbers in subsections and correcting some indenting). The only piece I can't seem to figure out is making the dots clickable along with the text and page number.

Here is the self-contained MWE: (Keep in mind it's a bit long because part of the problem is the package interaction, so I need to include them all with their settings to make sure any potential solutions avoid package conflicts).

\usepackage[linktoc=all]{hyperref}% Use this to provide intra-pdf hyperlinking and better toc
                                  % linktoc=all used to extend the hyperlink across the dotted lines.... in theory.
\hypersetup{%               % Setup the coloring of the links. 
%                           % Currently the only necessary one is "colorlinks=true" and "linkcolor=blue".
    colorlinks   = true,    % Colours links instead of ugly boxes
    urlcolor     = blue,    % Colour for external hyperlinks
    linkcolor    = blue,    % Colour of internal links
    citecolor    = blue     % Colour of citations, could be ``red''

\usepackage{titlesec}% Use this to manipulate default chapter styling

\doublespacing% Make everything double spaced by default.
\preto\longtable{\par\singlespacing}% Pre-append using longtables to make sure that tables are single spaced.
\preto\itemize{\par\singlespacing}% Pre-append singlespace to itemize to account for single space bullet point lists.

\renewcommand{\contentsname}{TABLE OF CONTENTS}%


\renewcommand\cftchapfont{\normalfont}%         Remove Bold font from TOC
\renewcommand\cftchappagefont{\normalfont}%     Remove Bold font from TOC
\renewcommand\cftpartfont{\normalfont}%         Remove Bold font from TOC
\renewcommand\cftpartpagefont{\normalfont}%     Remove Bold font from TOC
\def\cftchapleader{\hyperlink{\mylabel}{\cftdotfill{\cftsecdotsep}}}% Add in the dotted lines between the name and page number in TOC

\setcounter{secnumdepth}{-1}% We don't want chapter numbers until later, 
                            % So let's kill off the table of contents depth detector until we want to start counting.

Some dedication stuff goes here.


Some Acknowledgements Text here.


\addcontentsline{toc}{chapter}{LIST OF TABLES}
%\addtocontents{toc}{\protect\contentsline{chapter}{LIST OF TABLES}{}{\@currentHref}}

\addcontentsline{toc}{chapter}{LIST OF FIGURES}
%\addtocontents{toc}{\protect\contentsline{chapter}{LIST OF FIGURES}{}{\@currentHref}}


Some Abbreviation text would go here.


Some Abstract text goes here.

\setcounter{secnumdepth}{3}% Now we want toc numbering.

\chapter{First real chapter}
Some intro or something else here

\section{A `section', toc should be indented some.}

Some section info.

\subsection{A `subsection', toc should be indented even more.}

\chapter{Second real chapter}
More text here.

\setcounter{secnumdepth}{-1}% We don't want the Appendix to have a number, but it should be linked.

\setcounter{secnumdepth}{3}% Now we number again.




To be clear, the specific line of interest is \def\cftchapleader{\hyperlink{\mylabel}{\cftdotfill{\cftsecdotsep}}}% which is my last attempt at trying to get the dots to link to the correct spot using \hyperlink from the hyperref package. But even trying to update the \mylabel each section doesn't seem to allow links to be formed correctly, and neither does the \@currentHref. I suspect this is an expansion issue due to when the actual ToC is formed versus when the labels and things are formed.

  • 1
    Sorry I won't wander through the internet to get a class and a template and then spend an hour to sort out your code. Minimize your code, put all relevant data into your question and ask a specific question. Commented Feb 9, 2019 at 19:02
  • "A solution would be great, but explaining how \addtoconents and \contentsline commands work above (and why we need a \protect command in there too?) would be even better" Question: Where can I find useful docs on syntax for these commands. "Here is the relevant portion of my cls file" Already minimized the code. "You can find the full cls file here on github" Is a direct link to the cls file, no 'wandering of the internet' required. Sarcasm really wasn't necessary. If you didn't want to answer it, then don't. If you want me to cut down my question, then at least be polite about it.
    – Jason
    Commented Feb 9, 2019 at 20:04
  • I'll add a MWE shortly as I have actually solved almost all of my original problems in this question now. But to answer your question about the use of \At(Begin/End)Document commands... The document must be made out of certain files (one file for each "piece") and those elements must be compiled in a specific order. Rather than having a large template that requires people to make sure they use the \include commands in the correct order, I am taking in file names, and then using the \At(Begin/End)Document commands to force the compile in the correct order.
    – Jason
    Commented Feb 9, 2019 at 22:26
  • Your dots don't link to the correct pages. Commented Feb 9, 2019 at 23:51
  • Sorry for the confusion Ulrike; that is the question I'm asking. I generated the dots, and I can make them linked "somewhere" but I can't figure out how to link them to the correct page.
    – Jason
    Commented Feb 9, 2019 at 23:58

1 Answer 1


Use this to link the chapter dots to the correct pages:


You can remove all the hypertargets and \mylabel definitions etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .