I have modified the formatting of subsections in the toc, so that they appear in one line instead of separate lines. For this i used the titletoc package. Here is a MWE:
\documentclass{scrbook}
\usepackage{titletoc}
\titlecontents*{subsection}%
[3.8em]%
{\small\itshape}%
{\hyperlink{subsection.\thecontentslabel}{\thecontentslabel}\ }%
{}%
{\ \thecontentspage}%
[,\ ]%
[.]%
\usepackage[colorlinks=true,linktoc=all]{hyperref}
\begin{document}
\tableofcontents
\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\subsection{Another Subsection}
\clearpage
\section{Another Section}
\end{document}
This was very easy, but there are two problems:
- The subsection label is not included in the link. This is already fixed in the MWE with the help of the answer to this question: Common style for global TOC, LOF, LOT and titletoc partial TOCs (with hyperref & caption)
- The link to the section following the modified subsections points to the wrong location. In the MWE the link of '1.2 Another Section' points to '1.1.1 Subsection'.
I have not found a solution to the second problem. I have experimented with \phantomsection
without any success. I have read here that titletoc has some incompatibilities with hyperref and tried to implement the same behavior with the tocloft package. I managed to get something similar, but not quite right. The tocloft approach seems to be so much more convenient, if the links would work properly.
On a sidenote: The document i want to apply this to is rather large and is typeset with the classicthesis style.
I would appreciate any tips or solutions to this problem.
Best Answer
This is a workaround, (or hack ;-)), it seems, that
titletoc
screws up the hyperlinks of sections for some reason I have not figured out so far.I redefined the
\section
command to manually set the hyperlinks and a dummy hypertarget right after the section starts. It works for\section{}
and\section[]{}
commands, but not for\section*{}
, but this writes no entry to theTOC
, so this is something you can live with(???).I also used
\usepackage{classicthesis}
, which seems to come beforetitletoc
, otherwise the toc style is not used.