0

I'm trying to create table of contents with hyperref and dot-filled lines. However I don't want them to be in unnumbered chapters. I couldn't find the solution for my problem from similar questions so I decided to create the a one. Here is my MWE:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{tocloft}
\usepackage{hyperref}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\begin{document}

\chapter*{Abstract}
\addcontentsline{toc}{chapter}{Abstract}

\chapter*{Foreword}
\addcontentsline{toc}{chapter}{Foreword}

\newpage

\tableofcontents

\chapter{Introduction}

\chapter{Experiments}

\section{sec 1}

\section{sec 2}

\chapter{Conclusion}

\end{document}
  • Welcome to TeX SX! It can easily be done with the \titlecontents command, from package titletoc, which come with titlesec. See p. 14 of titlesec documentation. – Bernard Jun 12 at 14:08
  • Follow-up question: What if I want dots also away from first numbered chapter introduction? (This is actually the problem I need to solve) – T. Holmström Jun 12 at 14:32
  • This is probably harder. Are you sure your introduction has to be numbered? – Bernard Jun 12 at 14:49
0

Thank you for your MWE, it was a great help. Try the following changes, less any of my typos, to your MWE after the line \usepackage{hyperref}

%\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\begin{document}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchapdotsep}{\protect\cftnodots}}
\chapter*{Abstract}
 % then as before until
\tableofcontents
\addtocontents{toc}{\protect\renewcommand{\protect\cftchapdotsep}{\protect\cftdotsep}}
\chapter{Introduction}

The first \addtocontents tells the ToC that chapters have no dotted leaders. The second \addtocontents tells the ToC to use the normal dotted leaders for chapters. Any fragile commands in the argument of \addtocontentshave to be\protect` ed otherwise there will be strange results.

  • Thanks for the GREAT answer, it did the thing! The only tiny problem exists anymore. Font of the dots for the chapters is different (bigger and bolded) compared to the font of the dots for the sections. Probably I have to use same font but I don't know how – T. Holmström Jun 13 at 8:21
  • Now I found the solution and I will share it here if someone will be in same situation as I was. So, to show dots in toc after chapter xxx with same font as in section: \addtocontents{toc}{\protect\renewcommand{\protect\cftchapleader}{\protect\cftdotfill{\cftdotsep}}}. Again thanks to Peter Wilson for the great answer. Without it I would have never find the solution! – T. Holmström Jun 13 at 8:45

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.