[Tex/LaTex] Professional slashbox alternative

best practicestablestypography

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

table

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 third, 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}%
  \label{tab:addlabel}%
\end{table}%

Best Answer

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

almost original table

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}%
  \label{tab:addanotherlabel}%
\end{table}%

diagbox 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}%
  \label{tab:addlabel}%
\end{table}%

final diagbox 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?)