我尝试实现具有不同行颜色(灰色和白色)的紧凑表。我有以下一段代码,在秒表的左上角放置了意外的黑框,我相信这总是放在文档中的最新表中:
\documentclass[10pt,journal,compsoc]{IEEEtran}
\PassOptionsToPackage{table}{xcolor}
\usepackage{eulervm}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{enumitem}
\setlist{nosep}
\newlist{legal}{enumerate}{10}
\setlist[legal]{label*=\arabic*.}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\algrenewcommand{\algorithmiccomment}[1]{\hfill// #1}
\makeatletter
\def\algbackskip{\hskip-\ALG@thistlm}
\makeatother
\usepackage{setspace}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{lc}
\toprule\addlinespace[0pt]
\textbf{Method} & \textbf{Used Value} \\
\toprule\addlinespace[0pt] \rowcolor{gray!25}
$func1()$ & 1000 \\ \rowcolor{gray!25}
$func2()$ & 1000 \\
$func3()$ & 1000 \\ \rowcolor{gray!25}
\bottomrule
\end{tabular}
\end{table}
\begin{table}[H]
\centering
\caption{}\label{tab:tests}
\begin{tabular}{lcc}
\toprule
\addlinespace[0pt]
\textbf{Providers} & \textbf{No} & \textbf{Number} \\
\toprule\addlinespace[0pt] \rowcolor{gray!25}
$user\_1$ & 100 & 4 \\
$user\_2$ & 100 & 4 \\
$user\_3$ & 100 & 4 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
有趣的是,这里在表格的 [0,0] 网格处出现了一个黑框:
答案1
@daleif 评论已识别并解决了您的问题,但使用该包编写表格更简单(至少在我看来)。使用它,行的着色很简单,并且颜色条和表格规则之间没有间隙,这些规则由包(作为库加载)tabularray
确定。booktabs
tabularray
左列中的表格在数学模式下有第一列()我想知道您为什么选择这个),在文本模式下有第二行,表格中的其他行也是如此。
\documentclass[10pt,journal,compsoc]{IEEEtran}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
First column is in math mode:
\begin{table}[ht]
\centering
\begin{tblr}{colspec={Q[l, mode=math] c},
row{1} = {font=\bfseries, mode=text},
row{even} = {gray9}
}
\toprule
Method & Used Value \\
\midrule
func1() & 1000 \\
func2() & 1000 \\
func3() & 1000 \\
\bottomrule
\end{tblr}
\end{table}
\begin{table}[ht]
\centering
\caption{}
\label{tab:tests}
\begin{tblr}{colspec={Q[l, mode=math] c c},
row{1} = {font=\bfseries, mode=text},
row{even} = {gray9}
}
\toprule
Providers & N & Number \\
\midrule
user\_1 & 100 & 4 \\
user\_2 & 100 & 4 \\
user\_3 & 100 & 4 \\
\bottomrule
\end{tblr}
\end{table}
\newpage
First column is in text mode as others columns:
\begin{table}[ht]
\centering
\begin{tblr}{colspec={Q[l] c},
row{1} = {font=\bfseries},
row{even} = {gray9}
}
\toprule
Method & Used Value \\
\midrule
func1() & 1000 \\
func2() & 1000 \\
func3() & 1000 \\
\bottomrule
\end{tblr}
\end{table}
\begin{table}[ht]
\centering
\caption{}
\label{tab:tests}
\begin{tblr}{colspec={Q[l] c c},
row{1} = {font=\bfseries},
row{even} = {gray9}
}
\toprule
Providers & N & Number \\
\midrule
user\_1 & 100 & 4 \\
user\_2 & 100 & 4 \\
user\_3 & 100 & 4 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}