我正在尝试制作一个单元格具有彩色背景的表格。我正在使用\colorcell{}
,并且它可以在一行数字下正常工作。
但是,我需要在每个单元格中画两条线。为了画两条线,我测试了软件包makecell
,但单元格并没有完全填满颜色。
表格如下:
\documentclass{IEEEtran}
\ifCLASSOPTIONcompsoc
\usepackage[caption=false, font=normalsize, labelfont=sf, textfont=sf]{subfig}
\else
\usepackage[caption=false, font=footnotesize]{subfig}
\fi
\usepackage{graphicx}
%
\usepackage{makecell}
\makeatletter
% \newcommand\nst{\@setfontsize\nst\@vipt\@viipt}
% \newcommand\nst{\@setfontsize\nst{6}{7}}
\newcommand\nst{\@setfontsize\nst{6.31415}{7.1828}}
\makeatother
\usepackage{array}
\usepackage{tabularx}
\usepackage[symbol]{footmisc}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\usepackage{threeparttable}
\usepackage[dvipsnames]{xcolor}
\newcommand{\celdat}[1]{ \footnotesize \bf #1 }
\newcommand{\celdah}[1]{ \footnotesize \bf #1 }
\newcommand{\celda}[1]{\scriptsize #1}
\newcommand{\celdas}[1]{\nst #1}
\usepackage{colortbl}
\usepackage{enumerate}
\colorlet{l1}{Peach!100}
\colorlet{l2}{Green!80}
\colorlet{l3}{Cerulean!100}
\colorlet{l4}{Yellow!100}
\colorlet{lD1}{Peach!40}
\colorlet{lD2}{Green!40}
\colorlet{lD3}{Cerulean!40}
\colorlet{lD4}{Yellow!40}
\begin{document}
\renewcommand{\arraystretch}{1.2}
\begin{table}[t]
\begin{threeparttable}
\newcolumntype{?}{!{\vrule width 1pt}}
\renewcommand{\arraystretch}{1.7}
\setlength{\tabcolsep}{3pt} \centering
\caption{Accuracy [\%]. Brown, green, blue, yellow fills indicate L1 to L4 layouts; the lighter tones of colors indicate dropout added to layout. Unfilled cells
correspond to cases with ties.
} \label{ACCTAB}
\begin{tabular}{|c?c|c|c?c|c|c?c|c|c|}
\hline
\multicolumn{10}{|c|}{\celdah{Basic model}} \\ \hline &
\multicolumn{3}{c?}{\celda{Ideal}} & \multicolumn{3}{c?}{\celda{Simple}} &
\multicolumn{3}{c|}{\celda{Complex}} \\ \cline{2-10} & \celda{$d{=}2$} &
\celda{$d{=}2.5$} & \celda{$d{=}3$} & \celda{$d{=}2$} &
\celda{$d{=}2.5$} & \celda{$d{=}3$} & \celda{$d{=}2$} &
\celda{$d{=}2.5$} & \celda{$d{=}3$ } \\ \hline
\multicolumn{1}{|l?}{\celda{4 boxes} } & \celda{\cellcolor{l1}{99.95}} & \celda{\cellcolor{lD1}{99.7}} & \celda{\cellcolor{lD1}{99.55}} & \celda{\cellcolor{lD3}{99.5}} & \celda{\cellcolor{lD3}{99.15}} & \celda{\cellcolor{l1}{99}} &
\celda{\cellcolor{l1}{99.1}} &
\celda{99.1\tnote{\textdaggerdbl}} & \celda{\cellcolor{l4}{99.2}} \\ \hline
\multicolumn{1}{|l?}{\celda{8 boxes} } & \cellcolor{l3}{ \celdas{\makecell{85.35\\2.13} }} & \cellcolor{l1}{ \celdas{\makecell{80.15\\2.28} }} & \celdas{\cellcolor{l1}{ \makecell{79.1\\2.61} }} & \celda{\cellcolor{l1}{78.75}} & \celda{\cellcolor{lD2}{75.85}} & \celda{\cellcolor{lD2}{76.75}} &
\celda{\cellcolor{lD2}{76.1}} & \celda{\cellcolor{lD3}{76.2}} & \celda{\cellcolor{l3}{76.05}} \\ \hline
\multicolumn{1}{|l?}{\celda{16 boxes}} & \celdas{\cellcolor{l3}{ \makecell{62.1\\4.69} }} & \celdas{\cellcolor{lD2}{ \makecell{65.2\\4.52} }} & \celdas{\cellcolor{l2}{ \makecell{60.55\\5.64}}} & \celda{\cellcolor{l1}{53.5}} & \celda{\cellcolor{l3}{52.75}} & \celda{\cellcolor{l2}{52.2}} &
\celda{\cellcolor{lD4}{49.95}} & \celda{\cellcolor{l4}{50.05}} & \celda{\cellcolor{lD4}{51.55}} \\ \hline
\end{tabular}
\begin{tablenotes}
\footnotesize
\item[\textdagger] L1, L4, L1-D, L3-D
\item[\textdaggerdbl] L1, L3-D
\end{tablenotes}
\end{threeparttable}
\end{table}
\end{document}
我还减小了字体大小以使两行适合每个单元格。
答案1
一种方法是使用tabularray
包:
\documentclass{IEEEtran}
\usepackage{capt-of}
\usepackage[dvipsnames]{xcolor}
\usepackage{tabularray}
\NewTblrTheme{captionof}%
{%
\DefTblrTemplate{caption}{default}%
{\addtocounter{table}{-1}%
\captionof{table}{\InsertTblrText{caption}}%
}
}
\colorlet{l1}{Peach!100}
\colorlet{l2}{Green!80}
\colorlet{l3}{Cerulean!100}
\colorlet{l4}{Yellow!100}
\colorlet{lD1}{Peach!40}
\colorlet{lD2}{Green!40}
\colorlet{lD3}{Cerulean!40}
\colorlet{lD4}{Yellow!40}
\begin{document}
\begin{table}[ht]
\footnotesize
\begin{talltblr}[
theme = captionof,
caption = {Accuracy [\%]. Brown, green, blue, yellow fills indicate L1 to L4 layouts; the lighter tones of colors indicate dropout added to layout. Unfilled cells correspond to cases with ties.},
label = {tab:ACCTAB},
note{\textdagger} = {L1, L4, L1-D, L3-D},
note{\textdaggerdbl} = {L1, L3-D}
]{
hlines, vlines,
colspec = {Q[r] *{9}{X[c, m]}},
colsep=2pt,
row{1} = {font=\bfseries},
row{3} = {mode=math},
}
\SetCell[c=10]{c} {Basic model}
& & & & & & & & & \\
\SetCell[r=2]{c}
& \SetCell[c=3]{c} {Ideal}
& & & \SetCell[c=3]{c} {Simple}
& & & \SetCell[c=3]{c} {{{Complex}}}
& & \\
& d{=}2
& d{=}2.5
& d{=}3
& d{=}2
& d{=}2.5
& d{=}3
& d{=}2
& d{=}2.5
& d{=}3 \\
4 boxes
& \SetCell{bg=l1} 99.95
& \SetCell{bg=lD1} 99.7
& \SetCell{bg=lD1} 99.55
& \SetCell{bg=lD3} 99.5
& \SetCell{bg=lD3} 99.15
& \SetCell{bg=l1} 99
& \SetCell{bg=l1} 99.1
& 99.1\TblrNote{\textdaggerdbl}
& \SetCell{bg=l4} 99.2 \\
8 boxes
& \SetCell{bg=l3} {85.35\\ 2.13}
& \SetCell{bg=l1} {85.15\\ 2.28}
& \SetCell{bg=l1} {79.1\\ 2.61}
& \SetCell{bg=l3} 78.75
& \SetCell{bg=lD2} 75.85
& \SetCell{bg=lD2} 76.75
& \SetCell{bg=lD2} 76.1
& \SetCell{bg=lD3} 76.2
& \SetCell{bg=l3} 76.05 \\
16 boxes
& \SetCell{bg=l3} {62.1\\ 4.69}
& \SetCell{bg=lD2} {65.2\\ 4.52}
& \SetCell{bg=l2} {60.55\\ 5.64}
& \SetCell{bg=l1} 53.5
& \SetCell{bg=l3} 52.75
& \SetCell{bg=l2} 52.2
& \SetCell{bg=lD4} 49.95
& \SetCell{bg=l4} 50.05
& \SetCell{bg=lD4} 51.55 \\
\end{talltblr}
\end{table}
\end{document}
附录: 通过重新设计表格,可以获得更好的间距:
- 使列宽不同
- 在第一列添加列标题“框”,然后在下面的单元格中插入其数字:
% preamble as before
\begin{document}
\begin{table}[ht]
\footnotesize
\begin{talltblr}[
theme = captionof,
caption = {Accuracy [\%]. Brown, green, blue, yellow fills indicate L1 to L4 layouts; the lighter tones of colors indicate dropout added to layout. Unfilled cells correspond to cases with ties.},
label = {tab:ACCTAB},
note{\textdagger} = {L1, L4, L1-D, L3-D},
note{\textdaggerdbl} = {L1, L3-D}
]{
hlines, vlines,
colspec = {Q[c] *{3}{X[0.9,c, m] X[1.2, c, m] X[0.9,c, m]}},
colsep=2pt,
row{1} = {font=\bfseries},
row{3} = {mode=math},
}
\SetCell[c=10]{c} {Basic model}
& & & & & & & & & \\
\SetCell[r=2]{c,m} boxes
& \SetCell[c=3]{c} {Ideal}
& & & \SetCell[c=3]{c} {Simple}
& & & \SetCell[c=3]{c} {{{Complex}}}
& & \\
& d{=}2
& d{=}2.5
& d{=}3
& d{=}2
& d{=}2.5
& d{=}3
& d{=}2
& d{=}2.5
& d{=}3 \\
4 & \SetCell{bg=l1} 99.95
& \SetCell{bg=lD1} 99.7
& \SetCell{bg=lD1} 99.55
& \SetCell{bg=lD3} 99.5
& \SetCell{bg=lD3} 99.15
& \SetCell{bg=l1} 99
& \SetCell{bg=l1} 99.1
& 99.1\TblrNote{\textdaggerdbl}
& \SetCell{bg=l4} 99.2 \\
8 & \SetCell{bg=l3} {85.35\\ 2.13}
& \SetCell{bg=l1} {85.15\\ 2.28}
& \SetCell{bg=l1} {79.1\\ 2.61}
& \SetCell{bg=l3} 78.75
& \SetCell{bg=lD2} 75.85
& \SetCell{bg=lD2} 76.75
& \SetCell{bg=lD2} 76.1
& \SetCell{bg=lD3} 76.2
& \SetCell{bg=l3} 76.05 \\
16 & \SetCell{bg=l3} {62.1\\ 4.69}
& \SetCell{bg=lD2} {65.2\\ 4.52}
& \SetCell{bg=l2} {60.55\\ 5.64}
& \SetCell{bg=l1} 53.5
& \SetCell{bg=l3} 52.75
& \SetCell{bg=l2} 52.2
& \SetCell{bg=lD4} 49.95
& \SetCell{bg=l4} 50.05
& \SetCell{bg=lD4} 51.55 \\
\end{talltblr}
\end{table}
\end{document}
经过此更改表的一些内容: