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.

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!

share|improve this question
    
@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. –  Yiannis Lazarides Jan 19 '11 at 14:10
add comment

2 Answers 2

up vote 1 down vote accepted

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!

share|improve this answer
    
you can reduce the width of the left column with \backslashbox{\makebox[4em][l]{\rlap{\colorbox{orange}{Class venue $(w_1)$}}}}{...} –  Herbert Jan 19 '11 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:) –  Yiannis Lazarides Jan 19 '11 at 17:23
add comment
\documentclass{article}

\usepackage{picture,slashbox}

\begin{document}

\begin{tabular}{@{}c|*6c} 
\backslashbox[0pt][l]{}{}
  & \makebox(0,0)[lb]{\put(-1.25\tabcolsep,0){\llap{k}}}%
a & 0 & 1 & 2 & 3 \\\hline
\makebox(0,0){\put(0,2.25\normalbaselineskip){\rlap{n}}}%
0 & b & 1 & 2 & 3 & 4\\
1 & c & 1 & 2 & 3 & 4\\
2 & d & 1 & 2 & 3 & 4\\
\end{tabular}

\end{document}

alt text

share|improve this answer
    
Your answer is elegant for this particular case. –  morbusg Feb 4 '11 at 17:37
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.