[Tex/LaTex] list with dot leaders

leaderslists

I would like to create to create list with dot leaders.Each entry into the list essentially contains four parts: a number, a description, dot leaders and lastly another number. I want it to look like the following:enter image description here .
I have looked at various examples on this forum but most of the examples do not give me exactly what I want-the most common problem is that when the description is long it starts from extreme left of the next line. The list I am trying to generate is very similar to a table of contents.

Best Answer

(Encountered this question while searching for something else. In case there's still any interest in the answer…)

Exactly this problem is discussed in A Beginner's Book of TeX by Seroul and Levy, on page 48. (Having leaders, but without the long line overlapping into the page number area.) Their trick is to make the line narrower on the right, then typeset the page numbers beyond the end of that line using \rlap. So, a minor modification of Werner's answer:

\documentclass{article}
\begin{document}

\newcommand{\page}[1]{\rightskip=25pt \dotfill\rlap{\hbox to 25pt{\hfill#1}}\par}

\begin{itemize}
  \item[2.1] An example \page{21}
  \item[2.2] A longer example like this such that the line wraps down to the
    next line and the last entry gets wrapped to the next line \page{22}
  \item[2.31] Another example \page{132}
\end{itemize}

\end{document}

which produces:

Screenshot from PDF output

Related Question