我有一张表格,表格的行都是彩色的。当第一列或最后一列被着色时(如下所示),单元格之前或之后会出现难看的空白。我想删除这个空白(在这张图片中,它只出现在第一行,因为它是彩色的。但当最后一行被着色时,情况也一样。我不想在第一行和最后一行都有这个空白)。
脚本如下:
%README: this copy with comprehensive attack and defences description.
\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}
\ifCLASSOPTIONcompsoc
% IEEE Computer Society needs nocompress option
% requires cite.sty v4.0 or later (November 2003)
\usepackage[nocompress]{cite}
\else
% normal IEEE
\usepackage{cite}
\fi
\ifCLASSINFOpdf
\else
\fi
\usepackage{colortbl}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\newcommand*\rot{\rotatebox{90}}
\usepackage{tabularx}
\usepackage{msc}
\usepackage{xcolor}
\newcommand{\quotes}[1]{``#1''} %for qoutation marks
\DeclareRobustCommand*{\IEEEauthorrefmark}[1]{%
\raisebox{0pt}[0pt][0pt]{\textsuperscript{\footnotesize\ensuremath{#1}}}}
\begin{document}
\title{Test}
\maketitle
\begin{table}
\caption{mytable}
\label{table:mytable}
\begin{tabular}{ l *{45}{c} }
\toprule
& \multicolumn{3}{c}{B} \\
\cmidrule(lr){2-4}
\multicolumn{1}{c}{\multirow{-2}{*}[0.5ex]{A}}
& AAA & BBB & CCC \\
\midrule
\rowcolor[gray]{.9}
Text1 & \cmark & \cmark & \cmark \\
Text2 & \xmark & \cmark & \xmark \\
\rowcolor[gray]{.9}
Text3 & \cmark & \xmark & \xmark \\
Text4 & \cmark & \cmark & \cmark \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
间距可以使用\aboverulesep = 0.605mm
(调整除顶部规则之外的所有规则上方的分隔,并且它具有默认值为 0.4ex 或 0.605mm) 和\belowrulesep = 0.984mm
(调整除底部规则之外的所有规则下方的分隔,并且它具有默认值为 0.65ex 或 0.984mm)。
如果需要频繁移除分隔符,可以定义\newcommand{\midsepremove}{\aboverulesep = 0mm \belowrulesep = 0mm}
和\newcommand{\midsepdefault}{\aboverulesep = 0.605mm \belowrulesep = 0.984mm}
移除间距并将其重置为默认值。在tabular
环境之前使用\midsepremove
,在环境之后使用\midsepdefault
。这有助于将间距重置为默认值,并避免普通表格中的行过于拥挤。
%README: this copy with comprehensive attack and defences description.
\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}
\ifCLASSOPTIONcompsoc
% IEEE Computer Society needs nocompress option
% requires cite.sty v4.0 or later (November 2003)
\usepackage[nocompress]{cite}
\else
% normal IEEE
\usepackage{cite}
\fi
\ifCLASSINFOpdf
\else
\fi
\usepackage{colortbl}
\usepackage{array}
\usepackage{booktabs}
% The new commands
\newcommand{\midsepremove}{\aboverulesep = 0mm \belowrulesep = 0mm}
\midsepremove
\newcommand{\midsepdefault}{\aboverulesep = 0.605mm \belowrulesep = 0.984mm}
\midsepdefault
\usepackage{caption}
\captionsetup{justification=centering}
\usepackage{multirow}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{amssymb}% http://ctan.org/pkg/amssymb
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\newcommand*\rot{\rotatebox{90}}
\usepackage{tabularx}
\usepackage{msc}
\usepackage{xcolor}
\newcommand{\quotes}[1]{``#1''} %for qoutation marks
\DeclareRobustCommand*{\IEEEauthorrefmark}[1]{%
\raisebox{0pt}[0pt][0pt]{\textsuperscript{\footnotesize\ensuremath{#1}}}}
\begin{document}
\title{Test}
\maketitle
\begin{table}
\caption{mytable}
\label{table:mytable}
\centering
\midsepremove
\begin{tabular}{ l *{45}{c} }
\toprule
& \multicolumn{3}{c}{B} \\
\cmidrule(lr){2-4}
\multicolumn{1}{c}{\multirow{-2}{*}[0.5ex]{A}}
& AAA & BBB & CCC \\
\midrule
\rowcolor[gray]{.9}
Text1 & \cmark & \cmark & \cmark \\
Text2 & \xmark & \cmark & \xmark \\
\rowcolor[gray]{.9}
Text3 & \cmark & \xmark & \xmark \\
Text4 & \cmark & \cmark & \cmark \\
\bottomrule
\end{tabular}
\midsepdefault
\end{table}
\end{document}
无关:用于\centering
将表格置于标题下方的中心。此外,还用于\captionsetup{justification=centering}
更好地处理浮动标题的位置。
答案2
答案3
使用cellspace
包为S
列类型添加属性并将上方和下方的设置booktabs
规则空间设置为零:
\documentclass[compsoc, conference, letterpaper, 10pt, times]{IEEEtran}
\usepackage{pifont}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\usepackage[table]{xcolor}
\usepackage{booktabs, cellspace, multirow}
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{3pt}
\begin{document}
\begin{table}
\centering
\caption{Table title}
\label{tab:my important table}
\rowcolors{2}{}{gray!20}
\begin{tabular}{ l *{4}{Sc} }
\toprule
& \multicolumn{3}{Sc}{B} \\
\cmidrule(lr){2-4}
\multicolumn{1}{c}{\multirow{-2}{*}[1.5pt]{A}}
& AAA & BBB & CCC \\
\midrule
Text1 & \cmark & \cmark & \cmark \\
Text2 & \xmark & \cmark & \xmark \\
Text3 & \cmark & \xmark & \xmark \\
Text4 & \cmark & \cmark & \cmark \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案4
一个简单的解决方案与booktabs
环境tabularray
包:行颜色按预期工作。
请注意,您需要将修剪选项lr
放在方括号中。
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{pifont}% http://ctan.org/pkg/pifont
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\begin{document}
\begin{table}
\centering
\caption{mytable}
\label{table:mytable}
\begin{booktabs}{
colspec = {l*{3}{c}},
cell{1}{1} = {r=2}{c}, % multirow
cell{1}{2} = {c=3}{c}, % multicolumn
}
\toprule
A & B & & \\
\cmidrule[lr]{2-4}
& AAA & BBB & CCC \\
\midrule
\SetRow{gray9}
Text1 & \cmark & \cmark & \cmark \\
Text2 & \xmark & \cmark & \xmark \\
\SetRow{gray9}
Text3 & \cmark & \xmark & \xmark \\
Text4 & \cmark & \cmark & \cmark \\
\bottomrule
\end{booktabs}
\end{table}
\end{document}