# 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}}
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7013871669769287, "perplexity": 1494.0274217233402}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-43/segments/1634323585246.50/warc/CC-MAIN-20211019074128-20211019104128-00360.warc.gz"}