# Split a cell diagonally in a table to write proper titles

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}%


edit: The table is now shown as:

## 1 Answer

With package makecell you can obtain the following table:

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.

• Thanks for your answer but it is not working as the two words"Score and exp" are written on each other, could you please help me with that? – SMH Sep 16 '15 at 12:33
• @SMH, well, the showed table is generated by provided MWE. So it works! If you like to have other design as you asked for in your question (how to diagonal split cell), please elaborate this. I do not understand now, what it should look-out – Zarko Sep 16 '15 at 12:42
• I run the code on TeXworks and I don't know why it didn't show the same result .. I hope I can get the same result as shown in your figure – SMH Sep 16 '15 at 12:44
• @SMH, now I see, that in my MWE the last line of MWE €nd{document} is missed. I correct this now. Please test this code. If you still have a problems, please send error message which you receive. – Zarko Sep 16 '15 at 12:58
• I already added the end document before.. this wasn't my problem .. there is no error .. but the two words are overlapping with each other and with the diagonal line as well – SMH Sep 16 '15 at 13:00