问题描述
我想在 LaTeX 文档中制作如下所示的表格,并将其用作revtex4-2
其文档类:
article
奇怪的是,当我用作文档类 时,这些白色列不存在:
LaTeX 代码:
\documentclass[aps, twocolumn]{revtex4-2}
% \documentclass[twocolumn]{article}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table*}[]
\caption{}
\label{tab:my-table}
\begin{tabular}{ll|c|cc|c|c|ccc|c}
\rowcolor[HTML]{EFEFEF}
\cellcolor[HTML]{EFEFEF} &
\cellcolor[HTML]{EFEFEF} &
\multicolumn{8}{c|}{\cellcolor[HTML]{EFEFEF}Col3} &
\cellcolor[HTML]{EFEFEF} \\
\rowcolor[HTML]{EFEFEF}
\cellcolor[HTML]{EFEFEF} &
\cellcolor[HTML]{EFEFEF} &
AA &
\multicolumn{2}{c}{\cellcolor[HTML]{EFEFEF}BB} &
CC &
DD &
\multicolumn{3}{c|}{\cellcolor[HTML]{EFEFEF}EE} &
\cellcolor[HTML]{EFEFEF} \\
\rowcolor[HTML]{EFEFEF}
\multirow{-3}{*}{\cellcolor[HTML]{EFEFEF}Col1} &
\multirow{-3}{*}{\cellcolor[HTML]{EFEFEF}Col2} &
&
b.1 &
b.2 &
&
&
e.1 &
e.2 &
e.3 &
\multirow{-3}{*}{\cellcolor[HTML]{EFEFEF}Col4} \\ \hline
dat1 & 111 & 0.00 & 1.00 & 1.00 & & 1.00 & & 1.00 & & 111111.00 \\
\rowcolor[HTML]{EFEFEF}
dat2 & 222 & 0.00 & & 1.00 & 1.00 & 0.50 & & 1.00 & 1.00 & 222222.00 \\
dat3 & 333 & 0.00 & & & & & & & & 333333.00 \\
\rowcolor[HTML]{EFEFEF}
dat4 & 444 & 0.00 & & & & & & & & 4444444.00
\end{tabular}
\end{table*}
\end{document}
答案1
正如建议的那样此 StackExchange 讨论,nicematrix
完成工作!
\documentclass[aps, twocolumn]{revtex4-2}
\usepackage{booktabs}
\usepackage[table,xcdraw]{xcolor}
\usepackage{nicematrix}
\begin{document}
\begin{table*}[]
\centering
\begin{NiceTabular}{@{}ll|c|cc|c|c|ccc|c@{}}
\CodeBefore
\rowcolor{gray!10}{1-3}
\rowcolors{2}{gray!10}{white}
\Body
% \toprule
& & \Block{1-8}{Col3} & & & & & & & & \\
& & & \Block{1-2}{BB} & & & & \Block{1-3}{EE} & & & \\
Col1 & Col1 & AA & b.1 & b.2 & CC & DD & e.1 & e.2 & e.3 & Col4 \\
\midrule
dat1 & 111 & 0.00 & 1.00 & 1.00 & & 1.00 & & 1.00 & & 111111.00 \\
dat2 & 222 & 0.00 & & 1.00 & 1.00 & 0.50 & & 1.00 & 1.00 & 222222.00 \\
dat3 & 333 & 0.00 & & & & & & & & 333333.00 \\
dat4 & 444 & 0.00 & & & & & & & & 444444.00 \\
% \bottomrule
\end{NiceTabular}
\caption{Caption}
\label{tab:my_label}
\end{table*}
\end{document}
答案2
使用新的 LaTeX 3tabularray
软件包在一次编译后也能得到预期的结果。在 MWE 中,以下是软件包版本 2021K(2021-06-05):
\documentclass[aps, twocolumn]{revtex4-2}
\usepackage{multirow, tabularray}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table*}
\caption{}
\label{tab:my-table}
\begin{tblr}{colspec = {ll|c|cc|c|c|ccc|c},
colsep=4pt,
row{odd} = {bg=gray!30},
row{2} = {bg=gray!30},
rowsep=1pt,
}
\multirow{3}{*}{Col1}
& \multirow{3}{*}{Col2}
& \multicolumn{8}{c}{Col3} & \multirow{3}{*}{Col4} \\
& & AA & \multicolumn{2}{c}{BB} & CC & DD & \multicolumn{3}{c}{EE} & \\
& & & b.1 & b.2 & & & e.1 & e.2 & e.3 & \\
\hline
dat1 & 111 & 0.00 & 1.00 & 1.00 & & 1.00 & & 1.00 & & 111111.00 \\
dat2 & 222 & 0.00 & & 1.00 & 1.00 & 0.50 & & 1.00 & 1.00 & 222222.00 \\
dat3 & 333 & 0.00 & & & & & & & & 333333.00 \\
%
dat4 & 444 & 0.00 & & & & & & & & 4444444.00
\end{tblr}
\end{table*}
\end{document}