# Align leaders to the right end of the enclosing hbox?

Suppose I have an alignment with two columns of centered text. How can I add a \dotfill between these two columns? If I do this

\vbox{\halign{%
\hfil#\leaders\hbox to 5pt{\hfil.\hfil}\hskip 20pt plus 1 fil%
abc&defgh\cr%
a&b\cr%
abc&d\cr%
}}

I will get a random extra space between the dots at the border of the two columns, because the two adjacent \leaders commands each align to the left end of their enclosing hbox.

Is there a way to

• have halign use multiples of a specified unit for the column width,
• have \leaders (or maybe \cleaders) aligned to the right end of the enclosing hbox, or
• align leaders to an outer hbox rather than the directly enclosing hbox?

I know that I could work around the problem by using fixed-width columns rather than halign.

• @CroCo The code compiles if you add \bye to the end and compile in pdfTeX. – Steven B. Segletes Jan 4 '17 at 23:47
• @CroCo: It's plain TeX, so just use tex or pdftex... – user31729 Jan 4 '17 at 23:49
• I didn't pay attention to plaint-tex tag, sorry for inconvenience. I've removed my comment. – CroCo Jan 4 '17 at 23:52

One way would be to set the data twice, after the first setting measure the width of the first column, and then re-set forcing the first column to be a multiple of 5pt wide, rounding up the natural width. I added a , to your example as it maximised the gap at the cell boundary, as shown in the first alignment.

\vbox{\halign{%
\hfil#\leaders\hbox to 5pt{\hfil.\hfil}\hskip 20pt plus 1 fil%
abc&defgh\cr%
a&b\cr%
ab,c&d\cr%
}}

\bigskip
\tracingonline1

\setbox0\vbox{%
\global\setbox1\vbox{}%
\halign{%
\hfil#\hskip 20pt plus 1 fil%
&\hfil#\hfil\cr%
abc&defgh\cr%
a&b\cr%
ab,c&d\cr%
}
\setbox0\lastbox
\setbox0\hbox{\unhbox0\unskip\setbox0\lastbox\unskip}%
\count0=\wd0
\divide\count0 327680
\multiply\count0 5
\ifdim\count0 pt<\wd0
\fi
\xdef\colwidth{\the\count0 pt}%
}
\vbox{
\halign{%
\hbox to\colwidth{\hfil#\leaders\hbox to 5pt{\hfil.\hfil}\hskip 20pt plus 1 fil}%