TeX - LaTeX Asked on May 24, 2021
I have an horribly complex LaTeX table which I try to make a bit more readable.
I would like to use three different row colours, starting at the batch size column.
It is very difficult to do so, because every row consists of two rows (please ignore those zero values, they will soon change to meaningful values) and in the beginning, they are merged in packs of three.
The code is the following:
begin{tabular}{|c|c|l|l|l|l|}
hline
multirow{2}{*}{Modell} & multicolumn{1}{l|}{multirow{2}{*}{Batch size}} & multicolumn{4}{c|}{Learning rate} cline{3-6}
& multicolumn{1}{l|}{} & 0.05 & 0.10 & 0.15 & 0.20 hline
hline
cellcolor{white}multirow{6}{*}{Multilingual Flair} & multirow{2}{*}{16} & 0.7319 & 0.7705 & 0.7901 & textit{0.8316}
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
& multirow{2}{*}{32} & 0.631 & 0.681 & 0.7658 & 0.7747
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
& multirow{2}{*}{64} & 0.5919 & 0.6628 & 0.6676 & 0.7105
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 hline
multirow{6}{*}{BERT} & multirow{2}{*}{16} & 0.8113 & 0.8215 & 0.8279 & 0.8307
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
& multirow{2}{*}{32} & 0.7918 & 0.8236 & textbf{0.8338} & 0.8286
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
& multirow{2}{*}{64} & 0.7495 & 0.8008 & 0.8027 & 0.8128
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 hline
multirow{6}{*}{XLM-RoBERTa} & multirow{2}{*}{16} & 0.5972 & 0.5939 & 0.6351 & 0.6162
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
& multirow{2}{*}{32} & 0.5855 & 0.5929 & textit{0.6364} & 0.6057
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
& multirow{2}{*}{64} & 0.5641 & 0.5943 & 0.5989 & 0.6177
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 hline
end{tabular}
At the moment, it looks like that:
However, I would love to have it looking that way (with other colours for sure):
Are there any nice ideas out there how to do so?
The rowcolors{1}{grey!25}{white}
command seems to work only with two colours
With rowcolor
for each row and a different placement of the multirow
commands, you can achieve the following output. Personally, I'd prefer a different colorless approach that also removes almost all lines in the table. I have also included the code for this approach as well:
documentclass{article}
usepackage{geometry}
usepackage{multirow}
usepackage[table,svgnames]{xcolor}
% Just used in the second example table:
usepackage{booktabs}
usepackage{siunitx}
usepackage{makecell}
renewcommand{theadfont}{normalsize}
usepackage{etoolbox}
robustifybfseries
robustifyitshape
begin{document}
begin{tabular}{|c|c|l|l|l|l|}
hline
multirow{2}{*}{Modell} & multicolumn{1}{l|}{multirow{2}{*}{Batch size}} & multicolumn{4}{c|}{Learning rate} cline{3-6}
& multicolumn{1}{l|}{} & 0.05 & 0.10 & 0.15 & 0.20 hline
hline
rowcolor{LightYellow}cellcolor{white} & & 0.7319 & 0.7705 & 0.7901 & textit{0.8316}
rowcolor{LightYellow}cellcolor{white} & multirow{-2}{*}{16} & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
rowcolor{LightPink}cellcolor{white} & & 0.631 & 0.681 & 0.7658 & 0.7747
rowcolor{LightPink}cellcolor{white} & multirow{-2}{*}{32} & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
rowcolor{LightCyan}cellcolor{white} & & 0.5919 & 0.6628 & 0.6676 & 0.7105
rowcolor{LightCyan}cellcolor{white}multirow{-6}{*}{Multilingual Flair} & multirow{-2}{*}{64} & ±0.0 & ±0.0 & ±0.0 & ±0.0
hline
rowcolor{LightYellow}cellcolor{white} & & 0.8113 & 0.8215 & 0.8279 & 0.8307
rowcolor{LightYellow}cellcolor{white} & multirow{-2}{*}{16} & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
rowcolor{LightPink}cellcolor{white} & & 0.7918 & 0.8236 & textbf{0.8338} & 0.8286
rowcolor{LightPink}cellcolor{white} & multirow{-2}{*}{32} & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
rowcolor{LightCyan}cellcolor{white} & & 0.7495 & 0.8008 & 0.8027 & 0.8128
rowcolor{LightCyan}cellcolor{white}multirow{-6}{*}{BERT} & multirow{-2}{*}{64} & ±0.0 & ±0.0 & ±0.0 & ±0.0
hline
rowcolor{LightYellow}cellcolor{white} & & 0.5972 & 0.5939 & 0.6351 & 0.6162
rowcolor{LightYellow}cellcolor{white} & multirow{-2}{*}{16} & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
rowcolor{LightPink}cellcolor{white} & & 0.5855 & 0.5929 & textit{0.6364} & 0.6057
rowcolor{LightPink}cellcolor{white} & multirow{-2}{*}{32} & ±0.0 & ±0.0 & ±0.0 & ±0.0 cline{2-6}
rowcolor{LightCyan}cellcolor{white} & & 0.5641 & 0.5943 & 0.5989 & 0.6177
rowcolor{LightCyan}cellcolor{white} multirow{-6}{*}{XLM-RoBERTa} & multirow{-2}{*}{64} & ±0.0 & ±0.0 & ±0.0 & ±0.0
hline
end{tabular}
bigskip
sisetup{separate-uncertainty, table-format=1.4(5), detect-all}
setlength{tabcolsep}{0pt}
noindent
begin{tabular*}{textwidth}{@{extracolsep{fill}}lcSSSS}
toprule
thead{Modell} & thead{Batch size} & multicolumn{4}{c}{thead{Learning rate}}
cmidrule{3-6}
& & {0.05} & {0.10} & {0.15} & {0.20}
midrule
Multilingual Flair & 16 & 0.7319(1) & 0.7705(22) & 0.7901(333) & itshape 0.8316(4444)
& 32 & 0.631 & 0.681 & 0.7658 & 0.7747
& 64 & 0.5919 & 0.6628 & 0.6676 & 0.7105
addlinespace
BERT & 16 & 0.8113 & 0.8215 & 0.8279 & 0.8307
& 32 & 0.7918 & 0.8236 & bfseries 0.8338 & 0.8286
& 64 & 0.7495 & 0.8008 & 0.8027 & 0.8128
addlinespace
XLM-RoBERTa & 16 & 0.5972 & 0.5939 & 0.6351 & 0.6162
& 32 & 0.5855 & 0.5929 & itshape 0.6364 & 0.6057
& 64 & 0.5641 & 0.5943 & 0.5989 & 0.6177
bottomrule
end{tabular*}
end{document}
Correct answer by leandriis on May 24, 2021
A solution without multirow
, based on collcell
and stackengine
:
documentclass{article}
usepackage{amsmath}
usepackage[table, svgnames]{xcolor}
usepackage{multirow, hhline}
usepackage{collcell}
newcolumntype{L}{>{$collectcellVectorstack}l<{endcollectcell$}}
usepackage[usestackEOL]{stackengine}
setstackEOL{nl}
setlength{extrarowheight}{2pt}
begin{document}
begin{tabular}{|>{cellcolor{white}}c|>{cellcolor{white}}c|*{4}{L|}}
hline
&& multicolumn{4}{c|}{Learning rate}
hhline{|~|~|----|}
multirow{-2}{*}{Modell} & multirow{-2}{*}{Batch size} & 0.05 & 0.10 & 0.15 & 0.20
hlinehline
rowcolor{Wheat} & 16 & 0.7319nl pm 0.0 & 0.7705nl pm 0.0 & 0.7901nl pm 0.0 & textit{0.8316}nl pm 0.0
hhline{|~|-----|}
rowcolor{LavenderBlush}Multilingual Flair & 32 & 0.631nl pm 0.0 & 0.681nl pm 0.0 & 0.7658nl pm 0.0 & 0.7747nl pm 0.0
hhline{|~|-----|}
rowcolor{PowderBlue!50} & 64 & 0.5919nl pm 0.0 & 0.6628nl pm 0.0 & 0.6676nl pm 0.0 & 0.7105nl pm 0.0
hline
rowcolor{Wheat} & 16 & 0.8113 nl pm 0.0 & 0.8215nl pm 0.0 & 0.8279 nl pm 0.0 & 0.8307 nl pm 0.0 % cline{2-6}
hhline{|~|-----|}
rowcolor{LavenderBlush}BERT & 32 & 0.7918nl pm 0.0 & 0.8236nl pm 0.0 & textbf{0.8338}nl pm 0.0 & 0.8286nl pm 0.0
hhline{|~|-----|}
rowcolor{PowderBlue!50} & 64 & 0.7495nl pm 0.0 & 0.8008nl pm 0.0 & 0.8027nl p 0.0 & 0.8128nl pm 0.0
hline
rowcolor{Wheat} & 16 & 0.5972nl pm 0.0 & 0.5939nl pm 0.0 & 0.6351nl pm 0.0 & 0.6162nl pm 0.0
hhline{|~|-----|}
rowcolor{LavenderBlush}XLM-RoBERTa & 32 & 0.5855 nl pm 0.0 & 0.5929nl pm 0.0 & textit{0.6364}nl pm 0.0 & 0.6057 nl pm 0.0
hhline{|~|-----|}
rowcolor{PowderBlue!50} & 64 & 0.5641nl pm 0.0 & 0.5943nl pm 0.0 & 0.5989nl pm 0.0 & 0.6177nl pm 0.0
hline
end{tabular}
end{document}
Answered by Bernard on May 24, 2021
You can easily do that table with nicematrix
.
The output will be perfect in all the PDF viewers, at all levels of zoom (you won't have rules which seem to vanish).
However, you need several compilations (because nicematrix
uses PGF/Tikz nodes).
documentclass{article}
usepackage{nicematrix}
begin{document}
begin{NiceTabular}{ccllll}%
[
vlines ,
code-before =
rectanglecolor{yellow!15}{3-2}{4-6}
rectanglecolor{red!15}{5-2}{6-6}
rectanglecolor{blue!15}{7-2}{8-6}
rectanglecolor{yellow!15}{9-2}{10-6}
rectanglecolor{red!15}{11-2}{12-6}
rectanglecolor{blue!15}{13-2}{14-6}
rectanglecolor{yellow!15}{15-2}{16-6}
rectanglecolor{red!15}{17-2}{18-6}
rectanglecolor{blue!15}{19-2}{20-6}
]
Hline
Block{2-1}{Modell} & Block{2-1}{Batch size} & Block[c]{1-4}{Learning rate} Hline
& & 0.05 & 0.10 & 0.15 & 0.20
Hline
Block{6-1}{Multilingual Flair} & Block{2-1}{16} & 0.7319 & 0.7705 & 0.7901 & textit{0.8316}
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
& Block{2-1}{32} & 0.631 & 0.681 & 0.7658 & 0.7747
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
& Block{2-1}{64} & 0.5919 & 0.6628 & 0.6676 & 0.7105
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
Block{6-1}{BERT} & Block{2-1}{16} & 0.8113 & 0.8215 & 0.8279 & 0.8307
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
& Block{2-1}{32} & 0.7918 & 0.8236 & textbf{0.8338} & 0.8286
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
& Block{2-1}{64} & 0.7495 & 0.8008 & 0.8027 & 0.8128
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
Block{6-1}{XLM-RoBERTa} & Block{2-1}{16} & 0.5972 & 0.5939 & 0.6351 & 0.6162
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
& Block{2-1}{32} & 0.5855 & 0.5929 & textit{0.6364} & 0.6057
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
& Block{2-1}{64} & 0.5641 & 0.5943 & 0.5989 & 0.6177
& & ±0.0 & ±0.0 & ±0.0 & ±0.0 Hline
end{NiceTabular}
end{document}
Answered by F. Pantigny on May 24, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP