# Diagonal tabular cell questions

My MWE is adapted from How to diagonally divide a table cell … properly?.

Two questions:

1. I add an empiric rule of 0.71\baselineskip, but why 0.71?
2. Why c=... is not centered as the text below is?

Edit One ca see a simplified and corrected version here : Optional argument problem

\documentclass[10pt,french]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{array}
\usepackage{calc}
\usepackage{tikz,fourier}

\newcommand\diag[5]{%
\multicolumn{1}{|m{#2}|}{\hskip-\tabcolsep
\vcenter{\begin{tikzpicture}[baseline=0,anchor=south west,outer sep=0] \path[use as bounding box] (0,0) rectangle (#2+2\tabcolsep,\baselineskip); \node[minimum width={#2+2\tabcolsep-\pgflinewidth}, minimum height=\baselineskip+#3-\pgflinewidth] (box) {}; \draw[line cap=round] (box.north west) -- (box.south east); \node[anchor=south west,align=left,inner sep=#1] at (box.south west) {#4}; \node[anchor=north east,align=right,inner sep=#1] at (box.north east) {#5}; \end{tikzpicture}}\rule{0pt}{.71\baselineskip+#3-\pgflinewidth}\hskip-\tabcolsep}}

\begin{document}
\begin{tabular}{%
|>{\centering\arraybackslash}m{4.5cm}
|*{4}{>{\centering\arraybackslash}m{2.5em}|}}\hline
\diag{\tabcolsep}{4.5cm}{3.4em}{Coefficient\\ de frottement $c$}{Vitesse $V$\\ (en km/h)}&50&90&110&20\\ \hline
$c=0,8$\newline route s\eche, bitume neuf &&&&\\ \hline
$c=0,7$\newline route s\eche, bitume moyen &&&&\\ \hline
$c=0,8$\newline route mouill\'ee, bitume moyen &&&&\\ \hline
\end{tabular}
\end{document}

• Could 0.71 be an approximation to 1/\sqrt{2}=0.70710678...?
– Mico
Commented May 5, 2014 at 11:43
• @Mico As \strut definition is \rule[-.3\baselineskip]{0pt}{\baselineskip}, I thaught it came from hidden \strut ... Commented May 5, 2014 at 16:02

A solution with package diagbox:

\documentclass[10pt,french]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{array}
\usepackage{diagbox,ragged2e}
\usepackage{fourier}

\begin{document}
\begin{tabular}{%
|>{\Centering}m{4.5cm}
|*{4}{>{\Centering}m{2.5em}|}}\hline
\diagbox{\shortstack{Coefficient de\\ frottement $c$}}
{\shortstack{\vphantom{Ä}Vitesse $V$\\(en km/h)}} & 50 & 90 & 110 & 20 \\ \hline
$c=0,8$\newline route s\eche, bitume neuf &&&&\\ \hline
$c=0,7$\newline route s\eche, bitume moyen &&&&\\ \hline
$c=0,8$\newline route mouill\'ee, bitume moyen &&&&\\ \hline
\end{tabular}

\end{document}


Use \diag{\tabcolsep}{4.5cm}{0em}.... and in the \diagmacro set \rule{4pt}{0.71\baselineskip....} then you'll see that it is the height of the current line (without a the depth). The entried are left and right aligned, see the optional arguments of \node: align=.... Change it to align=center and it will no more be left/right aligned.

• @Herbet Thank you for your usefull answer, I learned of it. I still want to know the two points asked above. Commented May 5, 2014 at 15:56
– user2478
Commented May 6, 2014 at 6:40
• For the depth I agree with you, but for align=... it is not work. I speak about c=... in lines 2 to 4, there's no nodes here. Commented May 6, 2014 at 7:57
• Ah I see, a misunderstanding. Load package ragged2e and then \Centering, as seen in my example.
– user2478
Commented May 6, 2014 at 7:58

The environment {NiceTabular} of the package nicematrix has its own command \diagbox to deal with that kind of problem.

\documentclass[10pt,french]{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{nicematrix}
\usepackage{fourier}

\begin{document}

\begin{NiceTabular}{w{c}{4.5cm}*{4}{w{c}{2.5em}}}[hvlines,cell-space-limits=3pt]
\rule{0pt}{1cm}
\diagbox{Coefficient \\ de frottement $c$}
{Vitesse $V$\\(en km/h)} & 50 & 90 & 110 & 20 \\
\Block{}{$c=0,8$\\ route sèche, bitume neuf} \\
\Block{}{$c=0,7$\\ route sèche, bitume moyen} \\
\Block{}{$c=0,8$\\ route mouillée, bitume moyen} \\
\end{NiceTabular}

\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).