TransWikia.com

Dotfill Not Completely Filling Dots

TeX - LaTeX Asked on February 23, 2021

I am typesetting a book and am using dotfill to produce a sequence of dots extending to the displayed page number in the Table of Contents.

Alas, with the following (MWE) code

documentclass[12pt]{book}

usepackage{tocloft}

begin{document}

chapter*{textbf{TRANSLATOR'S PREFACE}}
addcontentsline{toc}{chapter}{textbf{Translator's Preface dotfill}}

newpage

tableofcontents
end{document}

I produce the following output:

enter image description here

Can somebody help me to remedy this so that the dots extend all the way to the page number as usual?

One Answer

This happens because tocloft already inserts a leader as part of setting a chapter in the ToC; it's just a blank leader (or hfill). And, butting these leaders together (a dotfill and hfill) just makes them share the distance between the end points. That's why your leader - dotfill - goes only half-way.

Remedy this by specifying the appropriate chapter leader using tocloft's style:

renewcommand{cftchapleader}{dotfill}

Remember to remove the dotfill from your addcontentsline insertion.

If you want it bold you can use:

renewcommand{cftchapleader{bfseries dotfill}}

Correct answer by Werner on February 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP