# halign and vertical spacings

Here is a somewhat simple \halign usage which show that I'm missing something:

\documentclass{article}

\begin{document}

\halign{&#\cr
\noalign{\hrule}
\rule{0.4pt}{4cm}&
\rule{1cm}{0.4pt}&
\vrule &
\rule{1cm}{0.4pt}\vbox{\hbox{x}\hbox{y}}\rule{1cm}{0.4pt}&
\vrule &
\rule{1cm}{0.4pt}\vbox{\hbox{x}\vskip 10pt\hbox{y}}\rule{1cm}{0.4pt}&
\vrule &
\rule{1cm}{0.4pt}\vbox{\hbox{1}\vskip 0pt plus 1filll\hbox{y}}\rule{1cm}{0.4pt}&
\vrule &
\rule{1cm}{0.4pt}\vtop{\hbox{x}\hbox{y}}\rule{1cm}{0.4pt}&
\vrule &
\rule{1cm}{0.4pt}\vtop{\hbox{x}\vskip 10pt\hbox{y}}\rule{1cm}{0.4pt}&
\vrule &
\rule{1cm}{0.4pt}\vtop{\hbox{x}\vskip 0pt plus 1filll\hbox{2}}\rule{1cm}{0.4pt}&
\vrule \cr
\noalign{\hrule}}

\end{document}


I'd have expected 1 to be near the top line, and 2 to be near the bottom one. So I've two related questions:

1. why doesn't the \vskip do what I expect (using \vspace or \vspace* does not change anything, note that it would have been even more confusing if it did)

2. by what could I replace the \vskip to get the behavior I expect? (perhaps also modifying the \vbox and \vtop invocations if, as I'm currently thinking, their use is preventing the available space to be seen by the \vskip)

Note that why I'm doing here is trying to understand TeX behavior, so an answer to 2. which has a \usepackage is not really what I expect.

  \vbox{\hbox{1}\vskip 0pt plus 1filll\hbox{y}}


is equivalent to

\vbox{\hbox{1}\vskip 0pt \hbox{y}}


as a box is always set with glue at its natural size unless you do something like

\vbox to 5in{\hbox{1}\vskip 0pt plus 1filll\hbox{y}}


when the glue would then stretch

By far the easiest way to get 1 effectively near the top and y at the bottom of a row would to make the "visible row" of the table (ie the space between your horizontal rules) into two rows of the \halign.

• Ah, that confirm the influence of vbox. Is it possible to get automatically the value? The vrule do not need an explicit constant. (your suggestion to split the row seems to hint that it would be difficult). – AProgrammer Dec 2 '15 at 16:14
• @AProgrammer colortbl can do this but it is just using \leaders which can stretch in both directions. To do it with text there are two common ways, (1) set up the \halign preamble so that it boxes each cell so that the size can be measured. (ams alignments do this, setting the entire table twice, the first just measuring the size of each cell) or (2) use the \pdfsavepos pdftex extension and use \noalign to save the vertical position of each row in the aux file, on the next run you know the actual size so you can use \vbox to xxx to force a vbox to be the full height of the row. – David Carlisle Dec 2 '15 at 16:22
• So the conclusion is that you either need multiple passes (directly or indirectly) or a priori knowledge of the size. Thanks. BTW, I assume that conclusion would also hold for the next thing I wanted a deeper look at: moving vertically the halign so that the baseline of an arbitrary row would be aligned with the baseline of the surrounding. – AProgrammer Dec 2 '15 at 16:35
• @AProgrammer anyone who's spent any time programming tex tables has told themselves (once they are a few years in and it's too late to change) that it would have been better not to have used \halign and simply maintain some data structure of stored boxes and do the alignments "by hand" at the macro layer. \halign makes simple things simple and only very slightly more complicated things impossibly difficult:-) – David Carlisle Dec 2 '15 at 16:40
• @AProgrammer as per your last comment, see this newsgroup thread where I have posted some code using \pdfsavepos which does exactly that. Code at this post – user4686 Dec 2 '15 at 16:46