\documentclass[12pt]{article}
\usepackage[ paperwidth=8.27in, paperheight=11.69in]{geometry}
\usepackage{booktabs, siunitx}
\usepackage[svgnames,table]{xcolor}
\usepackage{longtable}
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{tabular}{cc}
\toprule
\rowcolors{1}{}{gray!10}
\begin{tabular}{cccc}
\multicolumn{4}{c}{Replication I}\\
\midrule
a & bc & 1 & d\\
24.0 & 15.8 & 17.5 & 20.8 \\
ad & c & bd & b \\
27.5 & 24.3 & 22.5 & 18.3 \\
abc & cd & ab & ac \\
21.5 & 15.5 & 26.2 & 27.5 \\
abcd & acd & bcd & abd \\
28.5 & 30.5 & 28.9 & 24.5 \\
\midrule
\end{tabular} & \rowcolors{1}{}{gray!10} \begin{tabular}{cccc}
\multicolumn{4}{c}{Replication II}\\
\midrule
ab & abc & 1 & bd \\
12.1 & 14.5 & 10.5 & 13.5 \\
d & a & ac & bc \\
12.0 & 9.0 & 15.0 & 15.8 \\
c & abcd & cd & b \\
11.5 & 17.2 & 16.0 & 11.0 \\
bcd & ad & abd & acd \\
19.5 & 13.2 & 12.9 & 13.5 \\
\midrule
\end{tabular} \\
\rowcolors{1}{}{gray!10}
\begin{tabular}{cccc}
\multicolumn{4}{c}{Replication III} \\
\midrule
a & 1 & bcd & abcd \\
26.0 & 18.5 & 29.8 & 25.8 \\
acd & ac & c & abc \\
35.0 & 25.7 & 30.5 & 25.4 \\
cd & ab & d & ad \\
17.8 & 26.0 & 24.5 & 30.2 \\
bc & bd & abd & b \\
17.9 & 20.4 & 25.4 & 15.8 \\
\end{tabular} & \rowcolors{1}{}{gray!10}
\begin{tabular}{cccc}
\multicolumn{4}{c}{Replication IV} \\
\midrule
abcd & a & 1 & abc \\
34.5 & 35.4 & 32.5 & 30.9 \\
acd & bc & bcd & d \\
45.3 & 43.5 & 30.4 & 28.9 \\
c & cd & ac & b \\
38.0 & 37.5 & 29.8 & 32.5 \\
abd & ab & bd & ad \\
36.5 & 30.5 & 30.0 & 38.5 \\
\end{tabular} \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
我需要交替着色的行,但颜色要双倍。也就是说,我需要 2-3 行是灰色,4-5 行是白色,6-7 行是灰色,等等。
我应该怎么办?
答案1
一种可能的解决方案是使用\hiderowcolors
/ \showrowcolors
:
\documentclass[12pt]{article}
\usepackage[ paperwidth=8.27in, paperheight=11.69in]{geometry}
\usepackage{booktabs, siunitx}
\usepackage[svgnames,table]{xcolor}
\usepackage{longtable}
\usepackage{multirow}
\newcommand{\mytablecolor}{\rowcolors{2}{gray!10}{gray!10}}
\begin{document}
\begin{center}
\begin{tabular}{cc}
\toprule
\mytablecolor
\begin{tabular}{cccc}
\multicolumn{4}{c}{Replication I}\\
\midrule
a & bc & 1 & d\\
24.0 & 15.8 & 17.5 & 20.8 \\
\hiderowcolors ad & c & bd & b \\
27.5 & 24.3 & 22.5 & 18.3 \\
\showrowcolors abc & cd & ab & ac \\
21.5 & 15.5 & 26.2 & 27.5 \\
\hiderowcolors abcd & acd & bcd & abd \\
28.5 & 30.5 & 28.9 & 24.5 \\
\midrule
\end{tabular} &
\mytablecolor
\begin{tabular}{cccc}
\multicolumn{4}{c}{Replication II}\\
\midrule
ab & abc & 1 & bd \\
12.1 & 14.5 & 10.5 & 13.5 \\
\hiderowcolors d & a & ac & bc \\
12.0 & 9.0 & 15.0 & 15.8 \\
\showrowcolors c & abcd & cd & b \\
11.5 & 17.2 & 16.0 & 11.0 \\
\hiderowcolors bcd & ad & abd & acd \\
19.5 & 13.2 & 12.9 & 13.5 \\
\midrule
\end{tabular} \\
\mytablecolor
\begin{tabular}{cccc}
\multicolumn{4}{c}{Replication III} \\
\midrule
a & 1 & bcd & abcd \\
26.0 & 18.5 & 29.8 & 25.8 \\
\hiderowcolors acd & ac & c & abc \\
35.0 & 25.7 & 30.5 & 25.4 \\
\showrowcolors cd & ab & d & ad \\
17.8 & 26.0 & 24.5 & 30.2 \\
\hiderowcolors bc & bd & abd & b \\
17.9 & 20.4 & 25.4 & 15.8 \\
\end{tabular} &
\mytablecolor
\begin{tabular}{cccc}
\multicolumn{4}{c}{Replication IV} \\
\midrule
abcd & a & 1 & abc \\
34.5 & 35.4 & 32.5 & 30.9 \\
\hiderowcolors acd & bc & bcd & d \\
45.3 & 43.5 & 30.4 & 28.9 \\
\showrowcolors c & cd & ac & b \\
38.0 & 37.5 & 29.8 & 32.5 \\
\hiderowcolors abd & ab & bd & ad \\
36.5 & 30.5 & 30.0 & 38.5 \\
\end{tabular} \\
\bottomrule
\end{tabular}
\end{center}
\end{document}