4

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

output

\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}
2
  • 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 ...
    – Tarass
    Commented May 5, 2014 at 16:02

2 Answers 2

3

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}

enter image description here

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.

4
  • @Herbet Thank you for your usefull answer, I learned of it. I still want to know the two points asked above.
    – Tarass
    Commented May 5, 2014 at 15:56
  • see my edited answer
    – 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.
    – Tarass
    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
1

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

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .