# Professional slashbox alternative

Suppose I have the following table which lists conversion rules, where rows denote the input and columns denote the output type (so, for example, the conversion int8_t -> int16_t would use b, while int16_t -> int8_t would use g):

This answer lists alternatives for using a \slashbox (which is what I would have originally used), which seem much more professional. However, the second table in their example seems unintuitive/not clear to me, and with the thrid, the thing that bit me was that in their example, the domains of rows and columns are different and therefore it is not necessary to define whether rows map to rooms and columns to dates or vice versa.

With that in mind, the best I could come up with was the above, which does not look good (and uses a vertical line which I'd like to avoid, but without it the table's meaning wouldn't be clear at all). What would be a best practice to typeset such a table?

Code for the example above:

\begin{table}
\centering
\begin{tabular}{rr|rrrrrr}
\toprule
&       & \multicolumn{6}{c}{Output}                    \\
\midrule
&       & int8\_t & int16\_t & int32\_t & uint8\_t & uint16\_t & uint32\_t \\
\multirow{6}[0]{*}{\begin{sideways}Input\end{sideways}} & int8\_t & a     & b & c & d     & e & f \\
& int16\_t & g     & h & i & j     & k & l \\
& int32\_t & m     & n & o & p     & q & r \\
& uint8\_t & s     & t & u & v     & w & x \\
& uint16\_t & y     & z & a & b     & c & d \\
& uint32\_t & e     & f & g & h     & i & j \\
\bottomrule
\end{tabular}%
\end{table}%

• IMHO \midrule belongs after & & int8\_t & int16\_t & int32\_t & uint8\_t & uint16\_t & uint32\_t \\ . – Count Zero Apr 22 '13 at 12:29

First of all, as I suggested in my comment, I would rather have the \midrule one row below:

I think grouping 'Output' with the headers makes more sense, logically, just as you did with 'Input'.

As an alternative to the slashbox package there is diagbox. The description in the documentation states:

diagbox is a modern alternative of slashbox.

I also like it better, is easier to customize and the diagonal line (now drawn with pict2e) is much nicer. Here's an example using it:

\begin{table}
\centering
\begin{tabular}{l|*{6}r}
\toprule
\diagbox{Input}{Output} & int8\_t & int16\_t & int32\_t & uint8\_t & uint16\_t & uint32\_t \\
\midrule
int8\_t & a & b & c & d & e & f \\
int16\_t & g & h & i & j & k & l \\
int32\_t & m & n & o & p & q & r \\
uint8\_t & s & t & u & v & w & x \\
uint16\_t & y & z & a & b & c & d \\
uint32\_t & e & f & g & h & i & j \\
\bottomrule
\end{tabular}%
\end{table}%


Overall a good result, but I was a bit dissatisfied with the placement of 'Output', so I tweaked the table. (Fortunately, diagbox is rather flexible.) The final result I came up with is a heavily modified (but IMHO visually the most appealing) version:

\begin{table}
\centering
\begin{tabular}{l|*{6}r}
\toprule
%\backslashbox{Input}{Output} & int8\_t & int16\_t & int32\_t & uint8\_t & uint16\_t & uint32\_t \\
\diagbox[width=2.5cm, height=2.5cm]{\raisebox{5pt}{\hspace*{0.25cm}Input}}{\raisebox{-1.27cm}{\rotatebox{90}{Output}}} & \raisebox{-0.25cm}{\rotatebox{90}{int8\_t}} & \raisebox{-0.25cm}{\rotatebox{90}{int16\_t}} & \raisebox{-0.25cm}{\rotatebox{90}{int32\_t}} & \raisebox{-0.25cm}{\rotatebox{90}{uint8\_t}} & \raisebox{-0.25cm}{\rotatebox{90}{uint16\_t}} & \raisebox{-0.25cm}{\rotatebox{90}{uint32\_t}} \\
\midrule\\
\hspace*{0.25cm}int8\_t & a & b & c & d & e & f \\ \\
\hspace*{0.25cm}int16\_t & g & h & i & j & k & l \\ \\
\hspace*{0.25cm}int32\_t & m & n & o & p & q & r \\ \\
\hspace*{0.25cm}uint8\_t & s & t & u & v & w & x \\ \\
\hspace*{0.25cm}uint16\_t & y & z & a & b & c & d \\ \\
\hspace*{0.25cm}uint32\_t & e & f & g & h & i & j \\ \\
\bottomrule
\end{tabular}%
\end{table}%


On a final note, I believe vertical lines are sometimes necessary and I don't think there is anything wrong with using one here. It is a guide for the eye to help separate logical groups from each other (e.g. headers from raw data) in the table. (For a discussion see here: Why not use vertical lines ('|') in a tabular?)

No vertical rules and no vertical words. The column of inputs can be topped by the word "Input" and the output columns can be easily grouped. I suggest two possibilities.

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{l*{6}{c}}
\toprule
& \multicolumn{6}{c}{Output} \\
\cmidrule(lr){2-7}
Input & int8\_t & int16\_t & int32\_t & uint8\_t & uint16\_t & uint32\_t \\
\midrule
int8\_t & a & b & c & d & e & f \\
int16\_t & g & h & i & j & k & l \\
int32\_t & m & n & o & p & q & r \\
uint8\_t & s & t & u & v & w & x \\
uint16\_t & y & z & a & b & c & d \\
uint32\_t & e & f & g & h & i & j \\
\bottomrule
\end{tabular}

\bigskip

\begin{tabular}{l*{6}{c}}
\toprule
& \multicolumn{6}{c}{Output} \\
\cmidrule(lr){2-7}
Input & int8\_t & int16\_t & int32\_t & uint8\_t & uint16\_t & uint32\_t \\
\cmidrule(lr){1-1}
\cmidrule(lr){2-7}
int8\_t & a & b & c & d & e & f \\
int16\_t & g & h & i & j & k & l \\
int32\_t & m & n & o & p & q & r \\
uint8\_t & s & t & u & v & w & x \\
uint16\_t & y & z & a & b & c & d \\
uint32\_t & e & f & g & h & i & j \\
\bottomrule
\end{tabular}

\end{document}


• These two (first prefered) look best by far, IMHO, compared to all other answers. – Foo Bar Apr 23 '13 at 20:09
• @FooBar Thanks to the author of booktabs – egreg Apr 23 '13 at 20:11