[Tex/LaTex] How to align dotfill to the right

horizontal alignmentleadersnomenclature

I use the following command below to make my list of nomenclature to look like the list of contents, but I am a bit disturbed by the fact that the dots between the text belonging to a symbol in the list and the page on which to find the definition is aligned to the left, and not to the right as they seem to be in the table of contents. The question is thus if it is possible to modify the script below, or a dotfill command in general, to align the dots to the right instead of to the left, which seems to be default.

\makeatletter
\newcommand \Dotfill {\leavevmode \cleaders \hb@xt@ .75em{\hss .\hss }\hfill \kern \z@}
\makeatother

\usepackage[refpage, noprefix]{nomencl}
\renewcommand*{\pagedeclaration}[1]{\unskip\Dotfill \makebox[6mm][r]{\hyperpage{#1}}}

My list of nomenclature now looks like this (I added the green line to make it easier too se that the points are aligned to the left):

enter image description here

Best Answer

\leaders

If you need vertically aligned dots, then you need \leaders. It is also used by \@dottedtocline from the table of contents. There is a kind of invisible fixed grid of leader boxes (horizontal positions are fixed) and \leaders select the boxes whose width fits entirely in the wanted space.

  • (+) Vertical alignment.
  • (+) Overall equal distances between dots.
  • (−) A leader box with with w might not be shown if the space is smaller than 2 * w, depending on the horizontal position.

\cleaders

The leader boxes are tightly packed in the middle of the space, available space (smaller than the width of a leader box) is distributed at the left and right side. Example from "The TeXbook" with leader box of width 10pt and the available space of 56pt:

3pt box box box box box 3pt
  • (−) No vertical alignment of the leader boxes.
  • (+) Overall equal distances between dots.

\xleaders

The "extensible" leaders divides the available space in as many slots as possible and the leader boxes are put horizontally centered inside the slots. Example from "The TeXbook" with leader box of width 10pt and the available space of 56pt:

1pt box 1pt box 1pt box 1pt box 1pt box 1pt
  • (−) No vertical alignment of the leader boxes.
  • (−) Dot distances differ from one \xleader to another.
  • (+) Probably it looks best for single isolated instances.

Summary

If vertical alignment is needed (table of contents, nomenclature, ...), then \leaders is the right command.

Related Question