我正在尝试为一些实验所获得的一些结果建立一个表格。
我试图在我的乳胶文档中重新创建这个表格(不完全是,但它的整体外观)。
我已经完成了 99%,但是单元格颜色看起来不对。彩色单元格之间有垂直的白色间隙
这是我的乳胶表的代码:
\usepackage{setspace}
\usepackage{placeins}
\usepackage{array}
\renewcommand{\arraystretch}{1.5} % Adjust the vertical padding here
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{graphicx}
\begin{table}
\centering
\caption{Architecture Performances}
\begin{tabularx}{\textwidth}{|l|*{2}{>{\centering\arraybackslash}X}|*{2}{>{\centering\arraybackslash}X}|*{2}{>{\centering\arraybackslash}X}|*{2}{>{\centering\arraybackslash}X}|} % Add vertical lines
\hline
\multicolumn{1}{|c|}{\cellcolor{greyheader}Architecture} & \multicolumn{2}{c|}{\cellcolor{greenheader}Accuracy} & \multicolumn{2}{c|}{\cellcolor{blueheader}Precision} & \multicolumn{2}{c|}{\cellcolor{yellowheader}Recall} & \multicolumn{2}{c|}{\cellcolor{orangeheader}F1 Scores} \\
\cline{2-9}
& \cellcolor{greenheader}TL & \cellcolor{greenheader}PT & \cellcolor{blueheader}TL & \cellcolor{blueheader}PT & \cellcolor{yellowheader}TL & \cellcolor{yellowheader}PT & \cellcolor{orangeheader}TL & \cellcolor{orangeheader}PT \\
\hline
\cellcolor{greybody}VGG16 & \cellcolor{greenbody}0.8182 & \cellcolor{greenbody}0.7727 & \cellcolor{bluebody}0.8000 & \cellcolor{bluebody}0.7500 & \cellcolor{yellowbody}0.8000 & \cellcolor{yellowbody}0.7500 & \cellcolor{orangebody}0.8000 & \cellcolor{orangebody}0.7500 \\
\cellcolor{greybody}VGG19 & \cellcolor{greenbody}0.7273 & \cellcolor{greenbody}0.7955 & \cellcolor{bluebody}0.8000 & \cellcolor{bluebody}0.7619 &\cellcolor{yellowbody}0.6000 & \cellcolor{yellowbody}0.8000 & \cellcolor{orangebody}0.6667 & \cellcolor{orangebody}0.7805 \\
\cellcolor{greybody}ResNet50 & \cellcolor{greenbody}0.8409 & \cellcolor{greenbody}0.7045 & \cellcolor{bluebody}0.8824 & \cellcolor{bluebody}0.7059 & \cellcolor{yellowbody}0.7500 & \cellcolor{yellowbody}0.6000 & \cellcolor{orangebody}0.8108 & \cellcolor{orangebody}0.6486 \\
\cellcolor{greybody}ResNet152 & \cellcolor{greenbody}0.8182 & \cellcolor{greenbody}0.6591 & \cellcolor{bluebody}0.9286 & \cellcolor{bluebody}0.6316 & \cellcolor{yellowbody}0.6500 & \cellcolor{yellowbody}0.6000 & \cellcolor{orangebody}0.7647 &\cellcolor{orangebody} 0.6154 \\
\cellcolor{greybody}DenseNet121 & \cellcolor{greenbody}0.8182 & \cellcolor{greenbody}0.8409 & \cellcolor{bluebody}0.8750 & \cellcolor{bluebody}0.7826 & \cellcolor{yellowbody}0.7000 & \cellcolor{yellowbody}0.9000 & \cellcolor{orangebody}0.7778 & \cellcolor{orangebody}0.8372 \\
\cellcolor{greybody}DenseNet201 & \cellcolor{greenbody}0.8636 & \cellcolor{greenbody}0.7955 & \cellcolor{bluebody}0.8889 & \cellcolor{bluebody}0.7619 & \cellcolor{yellowbody}0.8000 & \cellcolor{yellowbody}0.8000 & \cellcolor{orangebody}0.8421 & \cellcolor{orangebody}0.7805 \\
\hline
\end{tabularx}
\end{table}
并且,由于单独的单元格颜色非常碍眼,因此下面是同一张表,但没有单元格颜色
\usepackage{setspace}
\usepackage{placeins}
\usepackage{array}
\renewcommand{\arraystretch}{1.5} % Adjust the vertical padding here
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{graphicx}
\begin{table}
\centering
\caption{Architecture Performances}
\begin{tabularx}{\textwidth}{|l|*{2}{>{\centering\arraybackslash}X}|*{2}{>{\centering\arraybackslash}X}|*{2}{>{\centering\arraybackslash}X}|*{2}{>{\centering\arraybackslash}X}|} % Add vertical lines
\hline
\multicolumn{1}{|c|}{Architecture} & \multicolumn{2}{c|}{Accuracy} & \multicolumn{2}{c|}{Precision} & \multicolumn{2}{c|}{Recall} & \multicolumn{2}{c|}{F1 Scores} \\
\cline{2-9}
& TL & PT & TL & PT & TL & PT & TL & PT \\
\hline
VGG16 & 0.8182 & 0.7727 & 0.8000 & 0.7500 & 0.8000 & 0.7500 & 0.8000 & 0.7500 \\
VGG19 & 0.7273 & 0.7955 & 0.8000 & 0.7619 & 0.6000 & 0.8000 & 0.6667 & 0.7805 \\
ResNet50 & 0.8409 & 0.7045 & 0.8824 & 0.7059 & 0.7500 & 0.6000 & 0.8108 & 0.6486 \\
ResNet152 & 0.8182 & 0.6591 & 0.9286 & 0.6316 & 0.6500 & 0.6000 & 0.7647 & 0.6154 \\
DenseNet121 & 0.8182 & 0.8409 & 0.8750 & 0.7826 & 0.7000 & 0.9000 & 0.7778 & 0.8372 \\
DenseNet201 & 0.8636 & 0.7955 & 0.8889 & 0.7619 & 0.8000 & 0.8000 & 0.8421 & 0.7805 \\
\hline
\end{tabularx}
\end{table}
答案1
tabularray
使用包(Q[co=1]
是列类型的同义词)的解决方案X
:
\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor, tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Architecture Performances}
\begin{tblr}{
colspec = { l *{8}{ Q[si={table-format=1.4},c,co=1] } },
row{1,2} = {guard},
stretch = 1.5,
% lines
vline{1} = {2-Z}{},
vline{2-Z} = {1-Z}{},
hline{1} = {2-Z}{},
hline{2,3,Z} = {1-Z}{},
% cell spans
cell{1}{2,4,6,8} = {c=2}{c},
% colors
cell{2}{1} = {}{gray8},
cell{1-2}{2-3} = {}{green8},
cell{1-2}{4-5} = {}{blue8},
cell{1-2}{6-7} = {}{yellow8},
cell{1-2}{8-9} = {}{brown8},
cell{3-Z}{1} = {}{gray9},
cell{3-Z}{2-3} = {}{green9},
cell{3-Z}{4-5} = {}{blue9},
cell{3-Z}{6-7} = {}{yellow9},
cell{3-Z}{8-9} = {}{brown9},
}
& Accuracy & & Precision & & Recall & & F1 Scores & \\
Architecture & TL & PT & TL & PT & TL & PT & TL & PT \\
VGG16 & 0.8182 & 0.7727 & 0.8000 & 0.7500 & 0.8000 & 0.7500 & 0.8000 & 0.7500 \\
VGG19 & 0.7273 & 0.7955 & 0.8000 & 0.7619 & 0.6000 & 0.8000 & 0.6667 & 0.7805 \\
ResNet50 & 0.8409 & 0.7045 & 0.8824 & 0.7059 & 0.7500 & 0.6000 & 0.8108 & 0.6486 \\
ResNet152 & 0.8182 & 0.6591 & 0.9286 & 0.6316 & 0.6500 & 0.6000 & 0.7647 & 0.6154 \\
DenseNet121 & 0.8182 & 0.8409 & 0.8750 & 0.7826 & 0.7000 & 0.9000 & 0.7778 & 0.8372 \\
DenseNet201 & 0.8636 & 0.7955 & 0.8889 & 0.7619 & 0.8000 & 0.8000 & 0.8421 & 0.7805 \\
\end{tblr}
\end{table}
\end{document}
答案2
{NiceTabular}
这是的解决方案nicematrix
。您需要进行多次编译。
无论您使用什么 PDF,无论缩放级别如何,您都不会看到细白线。
\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{nicematrix}
\usepackage{siunitx}
\begin{document}
\begin{table}\centering
\caption{Architecture Performances}
\renewcommand{\arraystretch}{1.8}
\begin{NiceTabular}{l*{8}{S[table-format=1.4]}}[corners,vlines]
\CodeBefore
\cellcolor{gray!30}{2-1}
\rectanglecolor{gray!15}{3-1}{*-1}
\rectanglecolor{green!30}{1-2}{2-3}
\rectanglecolor{green!15}{3-2}{*-3}
\rectanglecolor{blue!30}{1-4}{2-5}
\rectanglecolor{blue!15}{3-4}{*-5}
\rectanglecolor{yellow!30}{1-6}{2-7}
\rectanglecolor{yellow!15}{3-6}{*-7}
\rectanglecolor{brown!30}{1-8}{2-9}
\rectanglecolor{brown!15}{3-8}{*-9}
\Body
\Hline
& \Block{1-2}{Accuracy} & & \Block{1-2}{Precision} & & \Block{1-2}{Recall} & & \Block{1-2}{F1 Scores} & \\
\Hline
Architecture & {TL} & {PT} & {TL} & {PT} & {TL} & {PT} & {TL} & {PT} \\
\Hline
VGG16 & 0.8182 & 0.7727 & 0.8000 & 0.7500 & 0.8000 & 0.7500 & 0.8000 & 0.7500 \\
VGG19 & 0.7273 & 0.7955 & 0.8000 & 0.7619 & 0.6000 & 0.8000 & 0.6667 & 0.7805 \\
ResNet50 & 0.8409 & 0.7045 & 0.8824 & 0.7059 & 0.7500 & 0.6000 & 0.8108 & 0.6486 \\
ResNet152 & 0.8182 & 0.6591 & 0.9286 & 0.6316 & 0.6500 & 0.6000 & 0.7647 & 0.6154 \\
DenseNet121 & 0.8182 & 0.8409 & 0.8750 & 0.7826 & 0.7000 & 0.9000 & 0.7778 & 0.8372 \\
DenseNet201 & 0.8636 & 0.7955 & 0.8889 & 0.7619 & 0.8000 & 0.8000 & 0.8421 & 0.7805 \\
\Hline
\end{NiceTabular}
\end{table}
\end{document}
答案3
这是基于 的代码的略微改动版本colortblr
。请注意,我已加载hhline
包以避免出现问题\cline
。
\documentclass{article}
\usepackage{geometry}
\usepackage{array,hhline}
\usepackage[svgnames]{xcolor}
\usepackage{colortbl}
\usepackage{tabularx}
\colorlet{greyheader}{Gray!50} \colorlet{greybody}{greyheader!30}
\colorlet{greenheader}{LightGreen!60!Olive!60} \colorlet{greenbody}{greenheader!30}
\colorlet{blueheader}{CornflowerBlue!70} \colorlet{bluebody}{blueheader!30}
\colorlet{yellowheader}{Red!15!Yellow!40} \colorlet{yellowbody}{yellowheader!30}
\colorlet{orangeheader}{LightSalmon!70} \colorlet{orangebody}{orangeheader!30}
\begin{document}
\begin{table}[tbh]
\renewcommand{\arraystretch}{1.5}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}
\setlength{\extrarowheight}{-0.5pt}
\centering
\caption{Architecture Performances}\label{tab:lab}
\vspace{3pt}
\begin{tabularx}{\textwidth}{|
>{\columncolor{greybody}}l|
*{2}{>{\columncolor{greenbody}}X|}
*{2}{>{\columncolor{bluebody}}X|}
*{2}{>{\columncolor{yellowbody}}X|}
*{2}{>{\columncolor{orangebody}}X|}
}
\hhline{~|*8{-}}
\multicolumn{1}{c|}{}
& \multicolumn{2}{c|}{\cellcolor{greenheader}Accuracy}
& \multicolumn{2}{c|}{\cellcolor{blueheader}Precision}
& \multicolumn{2}{c|}{\cellcolor{yellowheader}Recall}
& \multicolumn{2}{c|}{\cellcolor{orangeheader}F1 Scores} \\
\hline
\cellcolor{greyheader}Architecture
& \cellcolor{greenheader}TL & \cellcolor{greenheader}PT
& \cellcolor{blueheader}TL & \cellcolor{blueheader}PT
& \cellcolor{yellowheader}TL & \cellcolor{yellowheader}PT
& \cellcolor{orangeheader}TL & \cellcolor{orangeheader}PT \\
\hline
VGG16 & 0.8182 & 0.7727 & 0.8000 & 0.7500 & 0.8000 & 0.7500 & 0.8000 & 0.7500 \\
VGG19 & 0.7273 & 0.7955 & 0.8000 & 0.7619 & 0.6000 & 0.8000 & 0.6667 & 0.7805 \\
ResNet50 & 0.8409 & 0.7045 & 0.8824 & 0.7059 & 0.7500 & 0.6000 & 0.8108 & 0.6486 \\
ResNet152 & 0.8182 & 0.6591 & 0.9286 & 0.6316 & 0.6500 & 0.6000 & 0.7647 & 0.6154 \\
DenseNet121 & 0.8182 & 0.8409 & 0.8750 & 0.7826 & 0.7000 & 0.9000 & 0.7778 & 0.8372 \\
DenseNet201 & 0.8636 & 0.7955 & 0.8889 & 0.7619 & 0.8000 & 0.8000 & 0.8421 & 0.7805 \\
\hline
\end{tabularx}
\end{table}
\end{document}