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:
- how many digits are at the end of the line
- 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}
\newcommand\myleaders{\leavevmode\kern3pt\leaders\hbox{.}\hfill\kern6pt}
\newcommand\mycleaders{\leavevmode\kern3pt\cleaders\hbox{.}\hfill\kern6pt}
\newcommand\myxleaders{\leavevmode\kern3pt\xleaders\hbox{.}\hfill\kern6pt}
% \def \mypara#1#2{\noindent#1~~\dotfill~~#2}
\def \mypara#1#2{\noindent#1\myleaders#2}
% \def \mypara#1#2{\noindent#1\mycleaders#2}
% \def \mypara#1#2{\noindent#1\myxleaders#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?