Tables – Creating Combined Header Cells

horizontal alignmenttablesvertical alignment

This question is closely related to at least two other ones; namely, Tables of numbers, and slashbox alternative.

What I'm after, is the horizontal- and vertical-alignment of row- and column-headers in the picture in the OP from the first mentioned question (re-included below).

There are some typographical points which haven't been satisfied in either questions answers:

  1. The $n$ column-header is horizontally aligned in the same way as the column-contents.
  2. The $k$ row-header is flush-right in its container box, and vertically aligned the same as its row-contents.

How would one achieve this?

I'm interested in any and all ways to achieve this; be it Plain, LaTeX, Context, Lua, PGF/TikZ, … whatever!


The way I'm thinking to achieve this, in terms of describing the steps in plain english, is that:

  1. Type in the $n$-header lowered by, say, 1em, so that it gets the natural width of the column, and the proper formatting assigned in the preamble (be it centered or flush left, for example). But act as if nothing had been done, so that it doesn't take space away from what comes after.
  2. Type in the $k$-header flush right. The vertical alignment should be right in relation to the row-contents automatically. Again, this shouldn't probably take any space, so act as if nothing's been done.
  3. Combine the above two boxes as one entity, \hss(?) apart from each other, and slash a line from the natural width of the box's (ideally the same as the natural width of the whole column?) lower right corner to the upper left.

But because my TeX-fu is seriously lacking, I am unable to express these requirements with TeX. Let alone understand wether this is the right approach at all!

Best Answer

Consider the figure below: alt text

The minimum width, you need to have the two words aligned and have a slash between them is the total width of the two words, plus a bit of margins.

Alignment can be achieved by adding a strut of a suitable width to one of the words as shown in the code below (base example is from slashbox alternative).

\documentclass{article}
\usepackage{slashbox,booktabs,xcolor,amsmath}
\begin{document}
\noindent
\begin{tabular}{|l||*{5}{c|}}\hline
\backslashbox{\colorbox{orange}{Class venue $(w_1)$}}{\colorbox{yellow}{\vrule height4.8ex width0pt Date $(w_2)$}}
&\makebox[3em]{5/31}&\makebox[3em]{6/1}&\makebox[3em]{6/2}
&\makebox[3em]{6/3}&\makebox[3em]{6/4}\\\hline\hline
Meeting Room &&&&&\\\hline
Auditorium &&&&&\\\hline
Seminar Room &&&&&\\\hline
\end{tabular}
\end{document}

I am sure that with a bit of perseverance one of our Mathematician members can prove, that it is impossible to construct typographically correct slash boxes!

Related Question