3

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%
    &\leaders\hbox to 5pt{\hfil.\hfil}\hfil#\hfil\cr%
  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.

  • 1
    @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
3

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.

enter image description here

\vbox{\halign{%
  \hfil#\leaders\hbox to 5pt{\hfil.\hfil}\hskip 20pt plus 1 fil%
    &\leaders\hbox to 5pt{\hfil.\hfil}\hfil#\hfil\cr%
  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
\advance\count0 5
\fi
\xdef\colwidth{\the\count0 pt}%
}
\vbox{
\halign{%
  \hbox to\colwidth{\hfil#\leaders\hbox to 5pt{\hfil.\hfil}\hskip 20pt plus 1 fil}%
    &\leaders\hbox to 5pt{\hfil.\hfil}\hfil#\hfil\cr%
  abc&defgh\cr%
  a&b\cr%
  ab,c&d\cr%
}
}

\bye

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.