TeX - LaTeX Asked on December 3, 2020
I am trying to set the vertical height of a row which uses diagbox
to be smaller, but past techniques such as setarstrut
and cellspace
appear to not be working thus far. In particular, I am able to almost create the table exactly as sought, but the the row with the diagonal is too tall. How exactly can one set this particular row to be a constant height (e.g. to match the height of the other rows)?
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{diagbox}
usepackage{amsmath}
begin{document}
centering
renewcommand{arraystretch}{1.25}
begin{tabular}{ |p{0.8cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}| }
hline
multicolumn{7}{|c|}{Table}
hline
backslashbox{$P_1$kern-1em}{kern-1em$P_2$} & $10$ & $50$ & $100$ &$500$ &$1000$ &$5000$
hline
$10$ & 0.0238 & 0.0238 & 0.0087 & 0.0238 & 0.0238 & 0.0238
hline
$50$ & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
hline
$100$ & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
hline
$500$ & 0.0238 & 0.0238 & 0.0065 & 0.0081 & 0.0083 & 0.0129
hline
end{tabular}
end{document}
The environement {NiceTabular}
of nicematrix
has a built-in command diagbox
which gives directly the expected output. Moreover, you have a key hvlines
which draws all the rules excepted in the blocks (multicolumn
here).
documentclass{article}
usepackage{nicematrix}
begin{document}
centering
renewcommand{arraystretch}{1.25}
begin{NiceTabular}{ |p{0.8cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|p{1.1cm}|>{arraybackslash}p{1.1cm}| }[hvlines]
multicolumn{7}{c}{Table}
diagbox{$P_1$}{$P_2$} & $10$ & $50$ & $100$ &$500$ &$1000$ &$5000$
$10$ & 0.0238 & 0.0238 & 0.0087 & 0.0238 & 0.0238 & 0.0238
$50$ & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
$100$ & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
$500$ & 0.0238 & 0.0238 & 0.0065 & 0.0081 & 0.0083 & 0.0129
end{NiceTabular}
end{document}
However, you need several compilations (because nicematrix
uses PGF/Tikz nodes).
Correct answer by F. Pantigny on December 3, 2020
Replace column type in the first column to c
:
documentclass{article}
usepackage{diagbox}
usepackage{siunitx}
begin{document}
centering
renewcommand{arraystretch}{1.25}
begin{tabular}{ |c| *{6}{S[table-format=1.4]|} }
hline
multicolumn{7}{|c|}{Table}
hline
backslashbox{$P_1$kern-1em}{kern-1em$P_2$}
& {10} & {50} & {100} & {500} & {1000} & {5000}
hline
10 & 0.0238 & 0.0238 & 0.0087 & 0.0238 & 0.0238 & 0.0238
hline
50 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
hline
100 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
hline
500 & 0.0238 & 0.0238 & 0.0065 & 0.0081 & 0.0083 & 0.0129
hline
end{tabular}
end{document}
Addendum: But, your table I would rather write as follows:
documentclass{article}
usepackage{booktabs, diagbox}
usepackage{siunitx}
usepackage[skip=0.333lineskip]{caption}
begin{document}
begin{table}[ht]
caption*{Table}
centering
begin{tabular}{S[table-format=3.0]
*{6}{S[table-format=1.4]} }
toprule
{multirow{2.2}{*}{$P_1$}}
& multicolumn{6}{c}{$P_2$}
cmidrule(l){2-7}
& {10} & {50} & {100} & {500} & {1000} & {5000}
midrule
10 & 0.0238 & 0.0238 & 0.0087 & 0.0238 & 0.0238 & 0.0238
50 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
addlinespace
100 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238 & 0.0238
500 & 0.0238 & 0.0238 & 0.0065 & 0.0081 & 0.0083 & 0.0129
bottomrule
end{tabular}
end{table}
end{document}
Answered by Zarko on December 3, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP