3

The code below produces a horizontal alignment with two columns and three lines (see first image below). The first column has its elements flush right and the second column has its elements flush left. The first line spans two columns so that its natural width is more than the total natural widths of the two columns. As a result the elements in the second column make up for the difference. My question is if it is possible to have the first column make up for the difference instead (see second image below).

\everycr{\noalign{\hrule}}%
\tabskip=0em
\halign{%
   \vrule#&
   \enskip\hrulefill\strut#\strut&
   \strut#\strut\hrulefill\enskip&
   \vrule#%
\cr
   &\omit\span\omit
      \enskip\hfil
      \strut{\bf Quantity}\strut
      \enskip\hfil&
\cr
   & 1&~litre&
\cr
   &10&~pcs&
\cr}
\bye

\halign before \halign after

  • 1
    When n columns are spanned, the first n–1 column widths are set with respect to the non spanned cells and the excess, if any, goes to to the last column. That's how \halign works, so the answer is no. – egreg Nov 1 '14 at 20:15
  • Did you read my answer? – egreg Nov 1 '14 at 20:59
3

On page 245 of the TeXbook, it is explained how the widths of columns are computed when some cells in them are spanned. The explanation ends with this note:

These formulas usually work fine, but sometimes they produce undesirable effects. For example, suppose that n = 3, w11 = w22 = w33 = 10, w12 = w23 = −∞, and w13 = 100; in other words, the columns by themselves are quite narrow, but there’s a big wide entry that’s supposed to span all three columns. In this case TeX’s formula makes w1 = w2 = 10 but w3 = 80 – t1t2, so all the excess width is allocated to the third column. If that’s not what you want, the remedy is to use \hidewidth, or to increase the natural width of the tabskip glue between columns.

So there's no way for automatically transfer the excess width in the first column, because the above behavior is built in.

3

enter image description here

You need to give \halign a bit of encouragement to put at least half the width in each column.

(you should stop the doubled hrule as well, not done here)

\everycr{\noalign{\hrule}}%
\tabskip=0em
\setbox0\hbox{\bf Quantity}


\halign{%
   \vrule#&
   \enskip\hrulefill\strut#\strut&
   \strut#\strut\hrulefill\enskip&
   \vrule#%
\cr
\omit&\omit\enskip\kern.5\wd0\relax&\omit\kern.5\wd0\relax\enskip\cr
   &\omit\span\omit
      \enskip\hfil
      \strut{\bf Quantity}\strut
      \enskip\hfil&
\cr
   & 1&~litre&
\cr
   &10&~pcs&
\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.