[Tex/LaTex] Split a cell diagonally in a table to write proper titles

tables

I am trying to split the "Score\exp" cell diagonally where I can write "score" in one half and "exp" in the other half, any ideas?

My code:

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{rrrrrrrr}
    \toprule
    Score\textbackslash{}exp & 1     & 2     & 3     & 4     & 5     & 6     & 7 \\
    \midrule
    1     & 1     & 2     & 3     & 4     & 5     & 6     & 7 \\
    2     & 2     & 2     & 2     & 2     & 2     & 2     & 2 \\
    3     & 3     & 3     & 3     & 3     & 3     & 3     & 3 \\
    4     & 4     & 4     & 4     & 4     & 4     & 4     & 4 \\
    5     & 5     & 5     & 5     & 5     & 5     & 5     & 5 \\
    6     & 6     & 6     & 6     & 6     & 6     & 6     & 6 \\
    7     & 7     & 7     & 7     & 7     & 7     & 7     & 7 \\
    8     & 8     & 8     & 8     & 8     & 8     & 8     & 8 \\
    9     & 9     & 9     & 9     & 9     & 9     & 9     & 9 \\
    10    & 10    & 10    & 10    & 10    & 10    & 10    & 10 \\
    11    & 11    & 11    & 11    & 11    & 11    & 11    & 11 \\
    12    & 12    & 12    & 12    & 12    & 12    & 12    & 12 \\
    13    & 13    & 13    & 13    & 13    & 13    & 13    & 13 \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

enter image description here

edit:
The table is now shown as:
enter image description here

Best Answer

With package makecell you can obtain the following table: enter image description here

Code of above table is:

\documentclass{article} %
\usepackage{booktabs,makecell}
\usepackage[margin=10pt,
            font=normalsize,
            labelfont=bf,
            labelsep=space,
            position=below]{caption} % 08_03_2014

    \begin{document}
\begin{table}[htbp]
    \centering
\caption{Add caption}
    \label{tab:mytable}
\begin{tabular}{c*{7}{r}}
    \specialrule{1pt}{0pt}{0pt}
\diaghead{Scoreexp}{Score}{exp} 
          & 1     & 2     & 3     & 4     & 5     & 6     & 7 \\
    \hline\addlinespace
    1     & 1     & 2     & 3     & 4     & 5     & 6     & 7 \\
    2     & 2     & 2     & 2     & 2     & 2     & 2     & 2 \\
    3     & 3     & 3     & 3     & 3     & 3     & 3     & 3 \\
    4     & 4     & 4     & 4     & 4     & 4     & 4     & 4 \\
    5     & 5     & 5     & 5     & 5     & 5     & 5     & 5 \\
    6     & 6     & 6     & 6     & 6     & 6     & 6     & 6 \\
    7     & 7     & 7     & 7     & 7     & 7     & 7     & 7 \\
    8     & 8     & 8     & 8     & 8     & 8     & 8     & 8 \\
    9     & 9     & 9     & 9     & 9     & 9     & 9     & 9 \\
    10    & 10    & 10    & 10    & 10    & 10    & 10    & 10 \\
    11    & 11    & 11    & 11    & 11    & 11    & 11    & 11 \\
    12    & 12    & 12    & 12    & 12    & 12    & 12    & 12 \\
    13    & 13    & 13    & 13    & 13    & 13    & 13    & 13 \\
    \bottomrule
\end{tabular}%
  \label{tab:addlabel}%
\end{table}
    \end{document}

Edit: For diagonal line in the far left top cell is used macro \diaghead from package makecell. About it is in package documentation on page 16 stated:

This package offers macro based on possibilities of picture environment.

\diaghead(<H ratio,V ratio>){hText set for column widthi}%
                            {hFirst headi}{hSecond headi}

where () sets the ratios like in \line command (digits from 1 up to 6). This argument is optional, the default ratio (\line direction) defined as (5,-2).

The {} defined by hand, for example: 1) sets the width, using longest text lines from both heads|in this case you must put \theadfont macro, if you use \thead's; 2) the longest text from the rest of column; 3) \hskip, even \hskip\hsize the case of p column (or X column in tabularx environment). The {} is head in lower corner (usually for first or very left column), {}|in the upper corner (head for the all right columns).

As you can see from code, for length of cell I select width of compounded word Scoreexp. Instead it you can split them into tow words or define ratio (in my MWE it is omitted) between height and width of cell. Select this option according to your taste.

Related Question