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.

I just bumped into a interesting command called \valign. It seems to be the sister of \halign, but the TeXbook seems to be rather shy on explaining its use. As is the TeX by Topic. They only mention it swaps the meaning of rows and columns in its use when compared to \halign. But given the following example:

\valign{&#\cr
How  & is\cr
this & supposed\cr
to   & work?\cr
}
\bye

the produced box is overfull; the second column starts only after the right margin!

So my question is: how is it supposed to be used; how can you change the start of the second (or third) column so it doesn't go out of the page? Also if you have some usage examples somewhere, that'd be great!

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

The short answer is that each entry is typeset in internal vertical mode, which implies that when you feed it horizontal mode material, as you have done, you get that material typeset as paragraphs, resulting in boxes of width \hsize. Hence the overfull you have noticed. Here is a slightly improved version of your example:

\valign{&\vfil\vbox{\parindent=0pt\hsize=20mm #}\vfil\cr
How  & is is is is is is is is is is is is is\cr
this & supposed\cr
to to to to to to to to to to to to to to to to  & work?\cr
}
\bye

As for a real-life useful example, I haven't got one (other than the single row example \valign{\vfil#\vfil\cr…} mentioned in the TeX book). Maybe someone else will have one.

share|improve this answer
2  
No one said that every primitive was useful: \outer is the classic example. –  Joseph Wright Jan 1 '11 at 21:13
1  
I did once find a good use case for \valign. For the 1990 TUG meeting in Cork I produced a pocket diary, which contained a tabular calendar for the year. Typesetting the blocks of months with rows labelled with the days of the week was done quite easily with \valign. –  Peter Flynn Mar 13 at 23:41
add comment

Here's a modification of Herbert's example that places each entry in an \hbox of natural width and then inserts \hfil between all of the columns by redefining \cr.

\def\cr{\crcr\noalign{\hfil}}
\valign{&\hbox{\strut#}\crcr
badness  & box& boxmaxdepth& cleaders& dp& everyhbox\cr
everyvbox& hbadness& hbox& hfuzz& hrule& ht& lastbox\cr
leaders& overfullrule& prevdepth& setbox& unhbox& unhcopy& unvbox\cr
unvcopy& vbadness& vbox& vfuzz& vrule& vsplit& vtop\cr
wd& xleaders\cr}
\unskip
\bye

Note the final \crcr that ends the alignment preamble and the \unskip that follows. The \unskip could be removed and the final \cr changed to a \crcr.

That same trick could be used to stick a fixed amount of space between columns (note that \tabskip glue goes between rows here) or the not-very-well-known \hbox spread construct can be used. This inserts an extra em of space between columns.

\valign{&\hbox spread1em{\strut#\hfil}\cr
badness  & box& boxmaxdepth& cleaders& dp& everyhbox\cr
everyvbox& hbadness& hbox& hfuzz& hrule& ht& lastbox\cr
leaders& overfullrule& prevdepth& setbox& unhbox& unhcopy& unvbox\cr
unvcopy& vbadness& vbox& vfuzz& vrule& vsplit& vtop\cr
wd& xleaders\cr}
\bye

It's worth pointing out that by starting the alignment with a &, it causes the entire preamble to be repeated.

share|improve this answer
add comment

An example from David Bausum's book

\valign{&\hbox to 1in{\vrule height9pt depth3pt width0pt#\hfil}\vfil\cr
badness  & box& boxmaxdepth& cleaders& dp& everyhbox\cr
everyvbox& hbadness& hbox& hfuzz& hrule& ht& lastbox\cr
leaders& overfullrule& prevdepth& setbox& unhbox& unhcopy& unvbox\cr
unvcopy& vbadness& vbox& vfuzz& vrule& vsplit& vtop\cr
wd& xleaders\cr}
\bye
share|improve this answer
1  
That's a good example. I was a little confused by the use of the \vrule at first, but it's basically a .5pt shifted \strut. –  TH. Feb 26 '11 at 23:34
add comment

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.