How to align consecutive \leaders properly?

Ref: Heiko's excellent description at https://tex.stackexchange.com/a/253303/25858:

  • \leaders sets the boxes at fixed grid position. It is intended for dots in the table of contents, for example. Then no matter, where the dots start, they are always vertically aligned.

  • \xleaders calculates, how many boxes are needed to fill the space without overfilling. Then the space is divided in equal sized segments and the box is horizontally centered. The example below fills the space 20 pt with a box of width 7 pt. Thus two boxes fit in the space and the result is a "dashed" line.

  • \cleaders. Since the "dash" effect of the previous version is sometimes not desirable, \cleaders moves the boxes in the middle and put the remaining unfilled space at both sides of the space to be filled.

The problem arises when the space to be filled is not an exact multiple of the leader-period. What to do? Grid align (\leaders), centered with excess space on the outside (\cleaders), or distribute excess space between cycles (\xleaders).

So, I changed all \leaders and \cleaders to \xleaders.

\documentclass{article}

\newlength{\dotskip}
\setlength{\dotskip}{1mm}

\begin{document}

A \hbox to 20\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}B

A \xleaders\hbox to \dotskip {\hss:\hss}\hfill B

A \xleaders\hbox to \dotskip {\hss.\hss}\hfill B

A \hbox to 5\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \xleaders\hbox to \dotskip {\hss.\hss}\hfill B


\bigskip
A \hbox to 20\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}B

A \xleaders\hbox to \dotskip {\hss:\hss}\hfill B

A \xleaders\hbox to \dotskip {\hss.\hss}\hfill B

A \hbox to 5\dotskip {\xleaders\hbox to \dotskip {\hss:\hss}\hfill}%
   \xleaders\hbox to \dotskip {\hss.\hss}\hfill B

\end{document}

enter image description here


First off, only \leaders guarantee alignment across different lines.

However, \leaders are guaranteed to be aligned when they share the enclosing box level.

Consider the following plain TeX example:

\parindent=0pt

\def\lb{\hbox{\kern1mm\hss.\hss\kern1mm}}

\hbox to 4cm{\leaders\lb\hfil}

\hbox{\kern3.7mm\hbox to 3.63cm{\leaders\lb\hfil}}

\vtop{
  \leavevmode\leaders\lb\hskip4cm\kern0pt\par
  \leavevmode\kern3.7mm\leaders\lb\hskip3.63cm\kern0pt\par
  \leavevmode\hbox to 4cm{\leaders\lb\hskip4cm}\par
  \leavevmode\hbox to 4cm{\kern3.7mm\leaders\lb\hskip3.63cm}\par
}

\bye

As you can see, the first two rows of periods are not aligned, whereas the last four are.

enter image description here

Tags:

Boxes

Leaders