Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

Eg.

% tabskip=0pt
\halign{&#\hfil\tabskip1em plus1em minus.5em\cr
  Foo&Bar&Baz\cr
  \noalign{\smallskip\hrule}
}
\bye

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

2 Answers 2

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
  Foo&&Bar&&Baz\cr
  \noalign{\smallskip\hrule}
}

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\amp{&}
\begingroup
  \def\gobbleamp\amp{} \everycr{\gobbleamp}
  \halign{&#\tabskip0pt\aftergroup\amp&#\hfil\tabskip1em plus1em minus.5em\cr\amp
    Foo&Bar&Baz\cr
    \noalign{\smallskip\hrule}
  }
\endgroup

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

\def\amp{&}
\halign{&#\tabskip0pt&\amp#\hfil\tabskip1emplus1emminus.5em\cr
  Foo&Bar&Baz\cr
  \noalign{\smallskip\hrule}
}

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
2  
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

 
discard

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.