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!

  • @morsbusg I think is more a matter of geometry. The only way to achieve this is by making the top header have a lot of extra depth and the row header much wider. This will vary depending on the actual words in the slashbox. Jan 19, 2011 at 14:10

2 Answers 2


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).

\backslashbox{\colorbox{orange}{Class venue $(w_1)$}}{\colorbox{yellow}{\vrule height4.8ex width0pt Date $(w_2)$}}
Meeting Room &&&&&\\\hline
Auditorium &&&&&\\\hline
Seminar Room &&&&&\\\hline

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!

  • you can reduce the width of the left column with \backslashbox{\makebox[4em][l]{\rlap{\colorbox{orange}{Class venue $(w_1)$}}}}{...}
    – user2478
    Jan 19, 2011 at 17:14
  • @Herbert You can kern and save a bit but in the end your total width of the box cannot be smaller than the widths of the two labels. You can observe that clearly in your example also. This is not good typography:) Jan 19, 2011 at 17:23



  & \makebox(0,0)[lb]{\put(-1.25\tabcolsep,0){\llap{k}}}%
a & 0 & 1 & 2 & 3 \\\hline
0 & b & 1 & 2 & 3 & 4\\
1 & c & 1 & 2 & 3 & 4\\
2 & d & 1 & 2 & 3 & 4\\


alt text

  • Your answer is elegant for this particular case.
    – morbusg
    Feb 4, 2011 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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