# Common style for global TOC, LOF, LOT and titletoc partial TOCs (with hyperref & caption)

I am currently writing my PhD thesis, and I have trouble defining a common style for my global TOC and the partial TOCs generated by titletoc.

Basically if you check the following MWE, I like the general style of the global TOC, in particular the fact that hyperref links include the labels. However, I find that the dotted lines in the global TOC are not dense enough, and prefer those of the partial TOCs.

\documentclass[12pt,a4paper]{book}

\usepackage{caption}
\usepackage{titletoc}
\usepackage{lipsum}

\renewcommand{\cleardoublepage}{\clearpage}

\newcommand{\PartialToc}{\vspace*{0.5pc}\vbox{\bf\large\noindent Chapter contents}\vspace*{0.3pc}\startcontents[chapters]\vspace*{0.3pc}\printcontents[chapters]{p}{1}{}\vspace*{0.3pc}}

\begin{document}

% Custom style for partial TOCs
\titlecontents{psection}[3.6em]{\small\bfseries}{\contentslabel{1.8em}}{}{\mdseries\titlerule*[0.25pc]{.}\contentspage\hspace*{1.8em}}{}
\titlecontents{psubsection}[6.0em]{\small}{\contentslabel{2.4em}}{}{\titlerule*[0.25pc]{.}\contentspage\hspace*{1.8em}}{}

\tableofcontents
\listoffigures
\listoftables

\chapter{Chapter 1}

\vfill
\lipsum[1-2]
\vfill\PartialToc\clearpage

\section{Section 1}
\lipsum[1]

\begin{figure}[t]
\caption{Figure 1}
\end{figure}

\section{Section 2}
\lipsum[1]
\subsection{Subsection 2.1}
\lipsum[1]
\subsection{Subsection 2.1}
\lipsum[1]
\section{Section 3}
\lipsum[1]

\begin{table}[t]
\caption{Table 1}
\end{table}

\end{document}


Therefore, I tried to increase the density of the dotted lines in the global TOC, by adding the following titletoc style declarations after \begin{document}:

\titlecontents{section}[3.8em]{}{\contentslabel{2.3em}}{\hspace*{-2.3em}}{\titlerule*[0.25pc]{.}\contentspage}{}
\titlecontents{subsection}[6.2em]{}{\contentslabel{2.9em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}


However, in this case, the hyperref links are changed, which I would like to avoid (no I am not a maniac...). Is there a way to achieve this ? And can this also be used to make the hyperref links in the partial TOCs include the labels ?

And as a subsidiary question, how do I assign the same style to entries in the List of Figures and List of Tables ?

-

The titlesec/titletoc packages are somewhat incompatible with hyperref, and you happened to run into such a situation.

To get the links on the labels in the ToCs back, we have to teach that to titletoc with:

\titlecontents{section}%
[3.8em]% left
{}% above code
{\hspace*{-2.3em}}% unnumbered entry format
{\titlerule*[0.25pc]{.}\contentspage}% filler page format
{}% below code

\titlecontents{subsection}%
[6.2em]%
{}%
{}%
{\titlerule*[0.25pc]{.}\contentspage}%
{}

% Custom style for partial TOCs
\titlecontents{psection}%
[3.6em]%
{\small\bfseries}%
{}%
{\mdseries\titlerule*[0.25pc]{.}\contentspage\hspace*{1.8em}}%
{}

\titlecontents{psubsection}%
[6.0em]%
{\small}%
{}%
{\titlerule*[0.25pc]{.}\contentspage\hspace*{1.8em}}%
{}


That is, the format of the contentslabel is changed from being simply \thecontentslabel to a proper hyperlink.

To obtain the narrow dots line in the LoT and LoF I would use package tocloft. This package can also handle the ToC, so you may find that titletoc is superfluous. Just use

\usepackage[titles]{tocloft}
\renewcommand{\cftdotsep}{0.3}

-
Thank you for your answer, this solution is working well for the global TOC and the partial TOCs. It even works with the listofalgorithms, which is unexpected, as it does not for the listoffigures and listoftables. I looked in the .lof and .lot files to look for the problem, and in those files the label format is different : figure.caption.<number> and table.caption.<number>. The problem is that this <number> is unrelated with the actual label of the figure or table. Any idea to have this solution work for the listoffigures and listoftables as well ? –  AldurDisciple Mar 1 '13 at 12:48
@AldurDisciple Could you then please update your MWE? There are several often used packages that interfere with LoT and LoF, so I need to see how you do it. –  mafp Mar 1 '13 at 13:39
Mmh, you're right, your solution was working with my initial MWE. I am using a lot of packages in my actual document, but it seems that the format modification is due to package caption. I updated my MWE accordingly. –  AldurDisciple Mar 1 '13 at 13:52
So, I have been desperately trying to understand why package caption changes the entry labels in the LOF and LOT files, but in vain for now... I tried using package tocloft as suggested, however it creates problems when used with package titletoc, which I need for the partial TOCs and to fix something in the page headers. –  AldurDisciple Mar 4 '13 at 15:12
@AldurDisciple Is it important? I updated my answer to style the LoT and LoF, and this works with caption, too. Do you need anything else? –  mafp Mar 4 '13 at 15:53

I found part of the answer to my question, related to the List of Figures and List of Table. In these lists, to assign the same style than in the TOC, you have to use the following commands.

\titlecontents{figure}[2.3em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}
\titlecontents{table}[2.3em]{}{\contentslabel{2.3em}}{}{\titlerule*[0.25pc]{.}\contentspage}{}


However, for some reason that I don't get, it has to be put before \begin{document}, otherwise it does not work.

-
Answering your own question is great. However you shouldn't ask a question inside your answer ;-) -- In my opinion you should provide a new question related to this one. –  Marco Daniel Mar 1 '13 at 10:54
I understand. I thought this would maybe update the question so that more people would be able to see it, but it didn't. I will remove it. –  AldurDisciple Mar 1 '13 at 12:33