# Alignment of \dotfill or \(c/x)leaders to page numbers wtih different amount of digits

I need to create something similar to Table of Contents manually. For that I need dot leaders to go from text of the "chapter" to page number of this "chapter". I tried to use either \dotfill, \leaders, \cleaders or \xleaders trying to achieve it.

With \dotfill I get this:

I want to align all dot leaders to the same point as "shortest" leaders row that lead to 3 digit number (130). On image you can see that those leaders are aligned to different point depending on:

1. how many digits are at the end of the line
2. length of text preceeding leaders even if number at the end of the line is the same

Second issue seems to get a bit better by replacing \dotfill to \leaders, but it is still present (unless it's just my eyes playing tricks on me), but using \leaders does not solve first issue:

I imagine that I could achieve perfect alignment by using something like tabular, but if at all possible I would like to keep it simple, without need for dealing with table.

Here is MWE showing everything I have tried so far, with commented \mypara definitions being alternatives which I tested:

\documentclass{book}

% \def \mypara#1#2{\noindent#1~~\dotfill~~#2}

\def \mycomment#1{\noindent\textbf{#1}:}

\begin{document}

\mycomment{1, 2 or 3 digits}

\mypara{This is a text}{1}

\mypara{This is a text}{30}

\mypara{This is a text}{130}

\mycomment{Different text}

\mypara{This is just short text}{30}

\mypara{This is a little bit longer text}{30}

\mypara{This is quite long text that goes on and on}{30}

\mycomment{1, 2 or 3 digits combined with different text}

\mypara{This is just short text}{1}

\mypara{This is a little bit longer text}{30}

\mypara{This is quite long text that goes on and on}{130}

\end{document}


How can I choose where \leaders or \dotfill ends regardless of how many digits are there at the end of the line?

• Set the number in a box of predetermined width. Jan 15 '16 at 9:43

\def\mypara#1#2{\noindent#1\myleaders\makebox[3mm][r]{#2}}