我有一张非常复杂的 LaTeX 表,我尝试让它更易读一些。
我想使用三种不同的行颜色,从批量大小列开始。
这样做非常困难,因为每一行都由两行组成(请忽略那些零值,它们很快就会变成有意义的值)并且在开始时,它们以三行一包的形式合并。
代码如下:
\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}
不过,我很想让它看起来像那样(当然还有其他颜色):
有没有什么好主意可以做到这一点?该\rowcolors{1}{grey!25}{white}
命令似乎只适用于两种颜色
答案1
对于\rowcolor
每一行,使用不同的命令位置\multirow
,您可以实现以下输出。就我个人而言,我更喜欢另一种无色方法,这种方法也会删除表中的几乎所有行。我也包含了这种方法的代码:
\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}
\robustify\bfseries
\robustify\itshape
\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}
答案2
multirow
一种不包含、基于collcell
和 的解决方案stackengine
:
\documentclass{article}
\usepackage{amsmath}
\usepackage[table, svgnames]{xcolor}
\usepackage{multirow, hhline}
\usepackage{collcell}
\newcolumntype{L}{>{$\collectcell\Vectorstack}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 \\
\hline\hline
\rowcolor{Wheat} & 16 & 0.7319\nl \pm 0.0 & 0.7705\nl \pm 0.0 & 0.7901\nl \pm 0.0 & \textit{0.8316}\nl \pm 0.0 \\
\hhline{|~|-----|}
\rowcolor{LavenderBlush}Multilingual Flair & 32 & 0.631\nl \pm 0.0 & 0.681\nl \pm 0.0 & 0.7658\nl \pm 0.0 & 0.7747\nl \pm 0.0 \\
\hhline{|~|-----|}
\rowcolor{PowderBlue!50} & 64 & 0.5919\nl \pm 0.0 & 0.6628\nl \pm 0.0 & 0.6676\nl \pm 0.0 & 0.7105\nl \pm 0.0 \\
\hline
\rowcolor{Wheat} & 16 & 0.8113 \nl \pm 0.0 & 0.8215\nl \pm 0.0 & 0.8279 \nl \pm 0.0 & 0.8307 \nl \pm 0.0 \\% \cline{2-6}
\hhline{|~|-----|}
\rowcolor{LavenderBlush}BERT & 32 & 0.7918\nl \pm 0.0 & 0.8236\nl \pm 0.0 & \textbf{0.8338}\nl \pm 0.0 & 0.8286\nl \pm 0.0 \\
\hhline{|~|-----|}
\rowcolor{PowderBlue!50} & 64 & 0.7495\nl \pm 0.0 & 0.8008\nl \pm 0.0 & 0.8027\nl \p 0.0 & 0.8128\nl \pm 0.0 \\
\hline
\rowcolor{Wheat} & 16 & 0.5972\nl \pm 0.0 & 0.5939\nl \pm 0.0 & 0.6351\nl \pm 0.0 & 0.6162\nl \pm 0.0 \\
\hhline{|~|-----|}
\rowcolor{LavenderBlush}XLM-RoBERTa & 32 & 0.5855 \nl \pm 0.0 & 0.5929\nl \pm 0.0 & \textit{0.6364}\nl \pm 0.0 & 0.6057 \nl \pm 0.0 \\
\hhline{|~|-----|}
\rowcolor{PowderBlue!50} & 64 & 0.5641\nl \pm 0.0 & 0.5943\nl \pm 0.0 & 0.5989\nl \pm 0.0 & 0.6177\nl \pm 0.0 \\
\hline
\end{tabular}
\end{document}
答案3
您可以使用 轻松制作该表nicematrix
。
在所有 PDF 查看器中,无论何种缩放级别,输出都将是完美的(不会出现似乎消失的规则)。
但是,您需要多次编译(因为nicematrix
使用 PGF/Tikz 节点)。
\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}