# How to set the width of last column in \settabs?

The last column in sample line in tabbed alignment is not used for anything. If we use sample line in \settabs, we must put there the widest cell for corresponding column (which may not be the first). But for last column this does not work. The width of the last column is determined by the width of the first row's last cell.

Why the width of the last column is not YY in example 1? And how to center Y in the cell?

Example 1:

\tt
\vrule\vbox{\hrule\settabs\+ \ XX \vrule&\cr
\+ \hfill\ X \hfill\strut\vrule& \ Y \hfill&\cr
\hrule
\+ \ XX \strut\vrule& \ YY \hfill&\cr
\hrule}\vrule
\bye


Example 2:

\tt
\vrule\vbox{\hrule\settabs\+ \ XX \vrule&\cr
\+ \hfill\ X \hfill\strut\vrule& \ Y \hfill&\cr
\hrule
\+ \ XX \strut\vrule& \ YY \cr
\hrule}\vrule
\bye


(of course it is better done with \halign, but I'm just curious if it can be done in \settabs)

Each field in a row is fixed size \hbox except the last one which is variable as there is no tab following to limit it. So just add another tab:

\settabs\+\ XX \vrule&\ YY &\cr


Edit:

After some experimenting with your examples, I've worked out what's going on. I've never used \settabs before, though.

\hfill doesn't eat the preceding space. It's not \hfill that caused the difference. If you look carefully, that's not the only difference between the two examples. The first example has \hfill& added and it's the & that makes the difference.

The first line of \settabs (that defines columns but doesn't print) has only one &, so the XXX column has fixed width, but the YYY column with no & afterwards is variable. The next row, one with X and Y, does have the second &; that fixes the width of the second column to the size specified, which is a Y and two spaces (followed by the third column that contains nothing).

Now to the row with XX and YY. Example 1 uses the second &, too, so the box is shrunken to match the one defined by the row with X and Y, so the row ends where you see it end. Example 2 doesn't have the second &, so the YY field's size is not fixed, therefore it's as wide as its natural size, the two Y and the two spaces. The two rows (they are \hbox-es) stacked in a \vbox, they make the \vbox as wide as the wider row, which is the bottom one.

• Why \hfill& after YY in the first example makes its output different from the output of the second example, which does not have this \hfill&? And the second \vrule must be removed from your answer, to match the example in the question. – Igor Liferenko Oct 21 '15 at 5:39
• Oh yes, I have put an extra \vrule. Anyway, the difference between examples is something to do with how different glues combine. I think the space is ignored before \hfill. On the other hand, \hfill in a variable \hbox is size zero: it won't stretch because it doesn't need to. – Heimdall Oct 21 '15 at 8:36
• I agree that the glue is zero. But can you prove that \hfill actually eats space in an example without \settabs? – Igor Liferenko Oct 21 '15 at 9:04
• Sorry, my mistake. \hfill does not eat the space. I've edited the answer explaining everything, also I've removed the extra \vrule. – Heimdall Oct 22 '15 at 14:29