# Dotted leader does not reach the page number in TOC

I am writing my thesis. The grad school requirement is that in TOC the dots leading to page number should extend till the number. I can get this by defining pnumwidth = 0 but then the problem is that all page numbers are left aligned. How can I keep then right align and still get the dots to end at the number (no gaps between number and dots for all entries)

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Aug 14 '14 at 20:04

EDIT: I came up with an automatic solution. Just add this to the preamble:

\usepackage{tocloft}
\usepackage{everypage}
\usepackage{calc}

\protect\cftsetpnumwidth{\widthof{\thepage}-.2em}
}}

This redifeines the pnumwidth at the beginning of every page to be the width of the actual page number. Its was a little too wide still, leaving a space between the leader and the number, so added the -.2em. I don't know why that is and perhaps someone can improve the code. I tested it on my ongoing project and it looks nice:

==================

I'm struggling with this myself at the moment. The thing I came up with is to first set the width of the page number box to be small. Then you compile the document and locate the 10th and the 100th page and change it there. This is made somewhat more easy with tocloft. A not so optimal solution but it works.

I'm using the calc package to get the with of numbers.

\documentclass{book}

\usepackage{tocloft}
\usepackage{calc}

\cftsetpnumwidth{\widthof{0}}
\begin{document}

\tableofcontents

\chapter{Some chapter}
\section{Some section}

\newpage
\setcounter{page}{10}