TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it somehow possible to set the \tabskip glue to zero for the first and last column in a repeated \halign?


% tabskip=0pt
\halign{&#\hfil\tabskip1em plus1em minus.5em\cr

There you can see that for the last column, there is a tabskip after it.

I would like to have a preamble which has zero tabskip for the first and last column. Is this somehow possible?

share|improve this question
up vote 6 down vote accepted

You can achieve what you wish by doubling the number of columns.

\halign{&#\tabskip0pt&#\hfil\tabskip1em plus1em minus.5em\cr

If the alignment is large, and you don't want to type & each time, it is possible to hide the extra & in the preamble and place it just after every & with \aftergroup. However, it needs to be removed after each \cr, hence the setting of \everycr. This, in turn, requires us to add a weird extra \amp after the first \cr.

  \def\gobbleamp\amp{} \everycr{\gobbleamp}
  \halign{&#\tabskip0pt\aftergroup\amp&#\hfil\tabskip1em plus1em minus.5em\cr\amp

Ha! I got some "eviler" method, with a nicer input.


The \amp is adding a & just after each & actually typed by the user.

TeX calls the part of a cell's preamble before # the "u-part", and the part after # the "v-part". Here, the \amp is in the u-part of the preamble for even cells. When such a cell starts, TeX expands the tokens to check for the presence of \omit. Once it sees (in our case) that there is no \omit, TeX inserts the u-part, hence an \amp. It then proceeeds with typesetting. \amp is expanded to &, which ends the cell. At this point, the v-part is inserted (\hfil). Then TeX starts the following odd cell after the & that the preamble had inserted.

Earlier, I was trying to put \amp in the v-part of the preamble for odd cells, naively equivalent: trying to insert & before each user-provided & instead of after. I don't fully understand why it doesn't work.

share|improve this answer
This is incredible wizardry. – Ryan Reich Oct 22 '11 at 15:59
@RyanReich: Thanks. You might prefer the new method I found (third code snippet) :D. – Bruno Le Floch Oct 22 '11 at 17:59

I suspect not. From TeX by Topic

The value of \tabskip that holds outside the alignment is used before the first column, and after all subsequent columns, unless the preamble contains assignments to \tabskip. Any assignment to \tabskip is executed while TeX is scanning the preamble; the value that holds when a tab character is reached will be used at that place in each row, and after all subsequent columns, unless further assignments occur. The value of \tabskip that holds when \cr is reached is used after the last column.

share|improve this answer
I was hoping there would've been some \unvbox-based magical solution for this, but oh well. Thanks! – morbusg Jan 1 '11 at 18:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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