我有这个示例表。我制作了下面的脚本,但我仍然需要一些我不知道如何满足的要求:
1)我需要在上面一行应用灰色(即包含单词 JOINT 的单元格)
2) 我希望\hline
(黑线) 在灰色上方可见。它们现在隐藏在列后面。
3)我需要删除最后一行灰色后面的多余白色
请编辑以下脚本:
\documentclass[10pt]{llncs}
\usepackage{colortbl} % for table colors
\usepackage{array}
\usepackage{booktabs}
\usepackage{makecell, booktabs, caption}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{adjustbox}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{sistyle} % for numbers
\SIthousandsep{,} % for numbers
\begin{document}
\title{Title}
\maketitle
\begin{abstract}
Abstract
\end{abstract}
\section{Section1}
\begin{table}[!tp]
\centering
\caption{Some table}
\label{tab:redirection}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{l@{\hspace{20pt}}>{\columncolor[gray]{0.8}}r>{\columncolor[gray]{0.8}}r@{\hspace{10pt}}rr@{\hspace{10pt}}rr}
\toprule
Row \#1
& \multicolumn{6}{c}{\num{111}} \\
\midrule
Row \#1 & \multicolumn{2}{c}{JOINT} &\multicolumn{2}{c}{Col\#1} & \multicolumn{2}{c}{Col\#2} \\
\hline
Row \#3
& \num{222}&(0.11\%) & \num{88} &(0.11\%) & \num{111} \\
\hline
Row \#4
& \num{555} & (0.33\%) & \num{222}& (0.11\%) & \num{22}& (0.11\%) \\
\bottomrule
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}
答案1
白色条纹来自 booktabs 规则上方和下方的填充。所以我将其设置为 0,并用 的小值替换它\extrarowheight
。至于上面的单元格,它来自这个单元格是 \multicolumn
。最后,我用 替换了 loading sistyle
。siunitx
所以我提出了这个代码:
\documentclass[10pt]{llncs}
\usepackage{colortbl} % for table colors
\usepackage{array}
\usepackage{booktabs}
\usepackage{makecell, booktabs, caption}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{adjustbox}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{siunitx}
\begin{document}
\title{Title}
\maketitle
\begin{abstract}
Abstract
\end{abstract}
\section{Section1}
\begin{table}[!tp]
\centering
\caption{Some table}
\label{tab:redirection}
\begin{adjustbox}{max width=\textwidth}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\extrarowheight}{2pt}
\begin{tabular}{l@{\hspace{20pt}}>{\columncolor[gray]{0.8}}r>{\columncolor[gray]{0.8}}r@{\hspace{10pt}}rr@{\hspace{10pt}}rr}
\toprule
Row \#1
& \multicolumn{6}{c}{\num{111}} \\
\midrule
Row \#1 & \multicolumn{2}{>{\columncolor[gray]{0.8}[2.8pt][1.4pt]}c@{\hspace{10pt}}}{JOINT} &\multicolumn{2}{@{\hspace{10pt}}c}{Col\#1} & \multicolumn{2}{c}{Col\#2} \\
\hline
Row \#3
& \num{222}&(0.11\%) & \num{88} &(0.11\%) & \num{111} \\
\hline
Row \#4
& \num{555} & (0.33\%) & \num{222}& (0.11\%) & \num{22}& (0.11\%) \\
\bottomrule
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}
答案2
(红线表示文本边框)
我不会使用adjustbox
。相反,最好使用tabular*
多width equal to text width. Color of
列cell should be defined by
单元格颜色。为了在列组之间留出更大的空间,我会插入额外的空列。
通过使用封装以及封装中cellspace
使用的线路,可以在单元内容的上方和下方获得更多的空间。\hlineB
boldline
\documentclass[10pt]{llncs}
\usepackage[table]{xcolor} % for table colors
\usepackage{array,
boldline, % part of shipunov bundle
cellspace,
makecell,
multirow}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\usepackage[skip=1ex]{caption}
\usepackage{multicol}
\usepackage{adjustbox}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\usepackage{sistyle} % for numbers
\SIthousandsep{,} % for numbers
\begin{document}
\section{Section1}
\begin{table}[!tp]
\centering
\caption{Some table}
\label{tab:redirection}
\setlength\tabcolsep{7pt}
\begin{tabular*}{\linewidth}{
Sl @{\extracolsep{\fill}}
c
*{2}{>{\columncolor{gray!80}\centering}p{3em}@{}}
c
*{2}{>{\centering}p{3em}}
c
*{2}{>{\centering\arraybackslash}p{3em}}
}
\hlineB{3}
Row \#1 & \multicolumn{9}{c}{\num{111}} \\
\hlineB{1.5}
Row \#1 && \multicolumn{2}{c@{}}{\cellcolor{gray!80}{JOINT}}
&& \multicolumn{2}{c}{Col\#1}
&& \multicolumn{2}{c}{Col\#2} \\
\hlineB{1.5}
Row \#3 && \num{222}
&(0.11\%)
&& \num{88}
& (0.11\%)
&& \num{111}
& \\
\hlineB{1.5}
Row \#4 && \num{555}
& (0.33\%)
&& \num{222}
& (0.11\%)
&& \num{22}
& (0.11\%) \\
\hlineB{3}
\end{tabular*}
\end{table}