# How to diagonally divide a table cell … adaptation?

I try to adapt this solution How to diagonally divide a table cell … properly? to my needs.

But I have a width problem 1\tabcolsep is too short, but anything longer is too long, should be 2\tabcolsep.

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}

\usepackage{array}
\usepackage{tabularx}
\usepackage{ragged2e}

\newcolumntype{C}[1]{>{\Centering}p{#1}}
\usepackage{tikz}

\newcommand\Tdiag[4]{%
\multicolumn{1}{|p{#2}|}{\hskip-\tabcolsep
\begin{tikzpicture}[%
baseline={(0,-.25\baselineskip)},
every node/.style={outer sep=0pt,inner sep=#1}]
\node[minimum width={#2+1\tabcolsep-\pgflinewidth},
minimum height=2\baselineskip-\pgflinewidth+\extrarowheight,
use as bounding box] (box) {};
\draw[line cap=round] (box.north west) -- (box.south east);
\node[anchor=south west,text width=.75*#2,align=left] at (box.south west) {#3};
\node[anchor=north east,text width=.75*#2,align=right] at (box.north east) {#4};
\end{tikzpicture}\hskip-\tabcolsep}}

\begin{document}

\begin{tabular}{|C{1.2cm}*{3}{|c}|}\hline
\Tdiag{.2em}{1.2cm}{\^Age}{Sexe}&
Féminin & Masculin & Totaux  \\\hline
15 ans&&1&\\\hline
16 ans & 16 & &  \\\hline
17 ans & 3 & &  \\\hline
Totaux & & & 36  \\\hline
\end{tabular}

\end{document}

• Are you really tied to this kind of obnoxious tables? ;-) – egreg Jan 5 '16 at 18:21
• It's for education purpose, not for a famous book. Sorry not to comply to the anglo-saxon table standart ;-) still an interesting point: why it doesn't work? – Tarass Jan 5 '16 at 18:27
• Why Anglo-Saxon? – Alenanno Jan 5 '16 at 18:30
• Has it another name ? – Tarass Jan 5 '16 at 18:42

You don't need TikZ for that. A simple diagbox package will do the trick:

\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{diagbox}

\begin{document}

\begin{table}\centering\setlength\tabcolsep{3.5pt}\renewcommand\arraystretch{1.25}
\noindent\makebox[\textwidth]{%
\begin{tabular}{|l|*{3}{c|}}
\hline
\diagbox[width=\dimexpr \textwidth/8+2\tabcolsep\relax, height=1cm]{ Âge }{Sexe}
& Féminin & Masculin & Totaux \\
\hline
15 ans & & 1 & \\
\hline
16 ans & 16 & & \\
\hline17 ans & 3 & & \\
\hline
Totaux & & & 36 \\
\hline
\end{tabular}
}%
\end{table}

\end{document}


• The labels are inverted. :P Also, I think they look better not being bold (as per the OP). – Alenanno Jan 5 '16 at 21:07
• @Alenanno: Thanks for pointing the inversion! I followed your advice as to boldness, it looks better indeed. – Bernard Jan 5 '16 at 21:13
• Thank you, but I still would like to understand why he tikz solution doesn't work. – Tarass Jan 6 '16 at 7:16
• Unfortunately I do not know enough about TikZ to give an answer/ – Bernard Jan 6 '16 at 8:51