表格:不使用非零 \aboverulesep 和 \belowrulesep 是否可以有垂直线和单元格颜色?

表格:不使用非零 \aboverulesep 和 \belowrulesep 是否可以有垂直线和单元格颜色?

在下表中,如何才能使垂直间距不为零\aboverulesep且不\belowrulesep破坏垂直线和单元格颜色?

使用默认垂直间距,表格就被毁了(见表 1);使用零\aboverulesep\belowrulesep垂直线以及单元格颜色“工作”,但垂直间距太窄(见表 2)。

换句话说:我如何修改表 2 以使其具有与表 1 相同的垂直间距?

谢谢并问候,豪尔赫。

更新:MWE 更改为更现实的情况(包括不与水平规则相邻的连续行)

示例(改进):

\documentclass{article}
\usepackage{newtxtext}
\usepackage{newtxmath}

% Roman subscripts
\catcode`_=\active
\newcommand{_}{\ifmmode\expandafter\sbrm\else\string_\fi}
\newcommand{\sbrm}[1]{\sb{\mathrm{#1}}}

% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage{xcolor,colortbl}
\definecolor{cellHighlightColor}{rgb}{0.933333333333333   0.956862745098039   0.984313725490196}
\newcolumntype{a}{>{\columncolor{cellHighlightColor}\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{b}{>{\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{d}{>{\centering\arraybackslash\leavevmode}p{\ColWidthWide}}
\newcolumntype{j}{@{\hspace{\ColIndentNormal}}l|}
\renewcommand{\arraystretch}{1.2}
\newlength{\ColWidthNormal}         \setlength{\ColWidthNormal}{1.40cm}
\newlength{\ColWidthWide}           \setlength{\ColWidthWide}{1.85cm}
\newlength{\ColIndentNormal}        \setlength{\ColIndentNormal}{6pt}
\newlength{\RuleWidthNormal}        \setlength{\RuleWidthNormal}{1.0pt}
\newlength{\RuleWidthThick}         \setlength{\RuleWidthThick}{1.5pt}

\begin{document}


% Table 1: good vertical spacing, ``cut'' cell coloring and vertical lines
\begin{table}[!ht]
\centering
\caption{Vertical spacing OK but cell colors and vertical lines appear ``cut''!}
\begin{small}
\begin{tabular}{
    @{\hspace{\ColIndentNormal}}p{1.20cm}
    >{\raggedleft\arraybackslash}p{0.90cm}@{\hspace{9pt}}|
    a|b|b|b|d|b
}
\midrule[\RuleWidthThick]
\multicolumn{2}{j}{}& & [17]& [12]& [5]& [13]& [14]\\
\multicolumn{2}{j}{}& & Moon& Shibata& Ali& {\small El-Chammas}& Ali \\
\multicolumn{2}{j}{}& \multirowcell{-3}{\textbf{This}\\\textbf{work}}& VLSI'17& ISSCC'17& VLSI'16& ISSCC'15& ISSCC'14\\
\midrule[\RuleWidthNormal]
\multicolumn{2}{j}{Resolution [b]}& \textbf{12}& 10& --& 14& 14& 14\\
\multicolumn{2}{j}{Technology [m]}& \textbf{28n}& 28n& 28n& 28n& 180n& 65n\\
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Supplies [V]}& \textbf{0.9}& 1.0& 1.8/$\pm$1.0& 2.5/1.8/0.9& 3.3/1.8& 3.3/2.5/1.2\\
\multicolumn{2}{j}{Input range [V$_{pp,d}$]}& \textbf{1.6}& --& 2.0& --& 2.5& 2.0\\
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Sampling rate [Hz]}& \textbf{600M}& 500M& 9G& 2.5G& 500M& 1G\\
\multicolumn{2}{j}{ERBW [Hz]}& \textbf{400M}& --& 1.125G& 1.5G& 700M& 1G\\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor}ENOB& LF in.& \textbf{9.51}& 9.1& --& 10.3& 10.5& 11.2\\
\rowcolor{cellHighlightColor}{[b]}& Nyquist& \textbf{9.45}& 9.1& 10.7& 10& 10.3& 11\\
\midrule
SNDR& LF in.& \textbf{59.0}& 56.7& --& 64& 64.8& 69\\
{[dB]}& Nyquist& \textbf{58.7}& 56.6& 66& 61.7& 64& 68\\
\midrule
SFDR& LF in.& \textbf{71.9}& 73& 79& 80& 93& 86\\
{[dBc]}& Nyquist& \textbf{72.4}& 69.2& 79& 73& 82& 82\\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Power [W]}& \textbf{14.5m}& 6m& 2330m& 1150m& 550m& 1200m\\
\multicolumn{2}{j}{FoM$_{W}$ [J/c.-step]}& \textbf{34.4f}& 22f& 715f& 463f& 849f& 585f\\
\multicolumn{2}{j}{FoM$_{S}$ [dB]}& \textbf{161.9}& 162.8& 152.3& 152.1& 150.6& 154.2\\
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Area [mm$^{2}$]}& \textbf{0.621}& 0.015& 5.1& 14.4& 2.5& 18\\
\midrule[\RuleWidthThick]
\end{tabular}
\end{small}
\end{table}


% Table 2: cell coloring and vertical lines OK, bad vertical spacing (too narrow)
\aboverulesep=0ex
\belowrulesep=0ex
\begin{table}[!ht]
\centering
\caption{Cell colors and vertical lines OK but vertical spacing is too narrow!}
\begin{small}
\begin{tabular}{
    @{\hspace{\ColIndentNormal}}p{1.20cm}
    >{\raggedleft\arraybackslash}p{0.90cm}@{\hspace{9pt}}|
    a|b|b|b|d|b
}
\midrule[\RuleWidthThick]
\multicolumn{2}{j}{}& & [17]& [12]& [5]& [13]& [14]\\
\multicolumn{2}{j}{}& & Moon& Shibata& Ali& {\small El-Chammas}& Ali \\
\multicolumn{2}{j}{}& \multirowcell{-3}{\textbf{This}\\\textbf{work}}& VLSI'17& ISSCC'17& VLSI'16& ISSCC'15& ISSCC'14\\
\midrule[\RuleWidthNormal]
\multicolumn{2}{j}{Resolution [b]}& \textbf{12}& 10& --& 14& 14& 14\\
\multicolumn{2}{j}{Technology [m]}& \textbf{28n}& 28n& 28n& 28n& 180n& 65n\\
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Supplies [V]}& \textbf{0.9}& 1.0& 1.8/$\pm$1.0& 2.5/1.8/0.9& 3.3/1.8& 3.3/2.5/1.2\\
\multicolumn{2}{j}{Input range [V$_{pp,d}$]}& \textbf{1.6}& --& 2.0& --& 2.5& 2.0\\
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Sampling rate [Hz]}& \textbf{600M}& 500M& 9G& 2.5G& 500M& 1G\\
\multicolumn{2}{j}{ERBW [Hz]}& \textbf{400M}& --& 1.125G& 1.5G& 700M& 1G\\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor}ENOB& LF in.& \textbf{9.51}& 9.1& --& 10.3& 10.5& 11.2\\
\rowcolor{cellHighlightColor}{[b]}& Nyquist& \textbf{9.45}& 9.1& 10.7& 10& 10.3& 11\\
\midrule
SNDR& LF in.& \textbf{59.0}& 56.7& --& 64& 64.8& 69\\
{[dB]}& Nyquist& \textbf{58.7}& 56.6& 66& 61.7& 64& 68\\
\midrule
SFDR& LF in.& \textbf{71.9}& 73& 79& 80& 93& 86\\
{[dBc]}& Nyquist& \textbf{72.4}& 69.2& 79& 73& 82& 82\\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Power [W]}& \textbf{14.5m}& 6m& 2330m& 1150m& 550m& 1200m\\
\multicolumn{2}{j}{FoM$_{W}$ [J/c.-step]}& \textbf{34.4f}& 22f& 715f& 463f& 849f& 585f\\
\multicolumn{2}{j}{FoM$_{S}$ [dB]}& \textbf{161.9}& 162.8& 152.3& 152.1& 150.6& 154.2\\
\rowcolor{cellHighlightColor}\multicolumn{2}{j}{Area [mm$^{2}$]}& \textbf{0.621}& 0.015& 5.1& 14.4& 2.5& 18\\
\midrule[\RuleWidthThick]
\end{tabular}
\end{small}
\end{table}

\end{document} 

输出(期望输出为表 2,其垂直间距与表 1 相同): 在此处输入图片描述

示例(原始):

\documentclass{article}
\usepackage{newtxtext}
\usepackage{newtxmath}
\usepackage{siunitx}

% Roman subscripts
\catcode`_=\active
\newcommand{_}{\ifmmode\expandafter\sbrm\else\string_\fi}
\newcommand{\sbrm}[1]{\sb{\mathrm{#1}}}

% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}

% Cell coloring
\usepackage{xcolor,colortbl}
\definecolor{cellHighlightColor}{rgb}{0.933333333333333   0.956862745098039   0.984313725490196}
\newcolumntype{a}{>{\columncolor{cellHighlightColor}\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{b}{>{\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcommand\ColoredCellOneByOne[1]{\multicolumn{1}{c}{\cellcolor{cellHighlightColor}{#1}}}

% Custom dimensions & default values
\renewcommand{\arraystretch}{1.2}
\newlength{\ColWidthNormal}         \setlength{\ColWidthNormal}{1.70cm}
\newlength{\ColIndentNormal}        \setlength{\ColIndentNormal}{6pt}
\newlength{\RuleWidthNormal}        \setlength{\RuleWidthNormal}{1.0pt}
\newlength{\RuleWidthThick}         \setlength{\RuleWidthThick}{1.5pt}


\begin{document}

% Table 1: good vertical spacing, ``cut'' cell coloring and vertical lines 
\begin{table}[!ht]
\centering
\caption{Vertical spacing OK but cell colors and vertical lines appear ``cut''!}
\begin{tabular}{@{\hspace{\ColIndentNormal}}p{2.5cm}|a|b|b|b}
\midrule[\RuleWidthThick]
\multicolumn{1}{c|}{Parameter} & Stage 1 & Stage 2 & Stage 3 & \ColoredCellOneByOne{Total}\\
\midrule[\RuleWidthNormal]
W$_{M_{Pi}}$, W$_{M_{Ni}}$ & \SI{16}{\micro\meter} & \SI{8}{\micro\meter} & \SI{8}{\micro\meter} & -- \\
\midrule
W$_{M_{Pbias}}$, W$_{M_{Nbias}}$ & -- & \SI{1.2}{\micro\meter} & -- & -- \\
\midrule
L$_{M_{Pi}}$, L$_{M_{Ni}}$ & \multicolumn{3}{c|}{\SI{30}{\nano\meter}} & -- \\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor} I$_{avg}$ @ \SI{600}{\mega\hertz} & \SI{1.5}{\milli\ampere} & \SI{0.6}{\milli\ampere} & \SI{100}{\micro\ampere} & \SI{2.2}{\milli\ampere} \\
\midrule
Gain & \SI{16}{\deci\bel} & \multicolumn{2}{c|}{\SI{26}{\deci\bel}} & \SI{42}{\deci\bel}\\
\midrule[\RuleWidthThick]
\end{tabular}
\end{table}

% Table 2: cell coloring and vertical lines OK, bad vertical spacing (too narrow)
\aboverulesep=0ex
\belowrulesep=0ex
\begin{table}[!ht]
\centering
\caption{Cell colors and vertical lines OK but vertical spacing is too narrow!}
\begin{tabular}{@{\hspace{\ColIndentNormal}}p{2.5cm}|a|b|b|b}
\midrule[\RuleWidthThick]
\multicolumn{1}{c|}{Parameter} & Stage 1 & Stage 2 & Stage 3 & \ColoredCellOneByOne{Total}\\
\midrule[\RuleWidthNormal]
W$_{M_{Pi}}$, W$_{M_{Ni}}$ & \SI{16}{\micro\meter} & \SI{8}{\micro\meter} & \SI{8}{\micro\meter} & -- \\
\midrule
W$_{M_{Pbias}}$, W$_{M_{Nbias}}$ & -- & \SI{1.2}{\micro\meter} & -- & -- \\
\midrule
L$_{M_{Pi}}$, L$_{M_{Ni}}$ & \multicolumn{3}{c|}{\SI{30}{\nano\meter}} & -- \\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor} I$_{avg}$ @ \SI{600}{\mega\hertz} & \SI{1.5}{\milli\ampere} & \SI{0.6}{\milli\ampere} & \SI{100}{\micro\ampere} & \SI{2.2}{\milli\ampere} \\
\midrule
Gain & \SI{16}{\deci\bel} & \multicolumn{2}{c|}{\SI{26}{\deci\bel}} & \SI{42}{\deci\bel}\\
\midrule[\RuleWidthThick]
\end{tabular}
\end{table}

\end{document}

输出(期望输出为表 2,其垂直间距与表 1 相同):

在此处输入图片描述

答案1

请尝试以下操作:

  • 序言补充

    \usepackage{cellspace}
    \setlength\cellspacetoplimit{7pt}
    \setlength\cellspacebottomlimit{7pt}
    
    \newcommand\mcl[1]{\multicolumn{2}{l|}{#1}} % for shorter table code
    
  • 将声明更改tabular为:

    \begin{table}[!htb]
    \aboverulesep=0ex
    \belowrulesep=0ex
    \centering
    \caption{Cell colors and vertical lines OK but vertical spacing is too narrow!}
    \small          % <--- changed
    \begin{tabular}{S{p{0.8cm}} S{p{1.5cm}}|
        >{\bfseries}a|b |b|b |d|b
                }
    

您将获得:

在此处输入图片描述

编辑(2): 使用您的“更现实”的表格,解决方案原理与以前相同(在答案的第一个版本中)。现在我稍微清理一下你的表格(通过定义新命令\mcl)。

在此处输入图片描述

\documentclass{article}
\usepackage{newtxtext}
\usepackage{newtxmath}

% Roman subscripts
\catcode`_=\active
\newcommand{_}{\ifmmode\expandafter\sbrm\else\string_\fi}
\newcommand{\sbrm}[1]{\sb{\mathrm{#1}}}

% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage[table]{xcolor}% <--- changed
\definecolor{cellHighlightColor}{rgb}{0.933333333333333   0.956862745098039   0.984313725490196}
\newcolumntype{a}{>{\columncolor{cellHighlightColor}\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{b}{>{\centering\arraybackslash\leavevmode}p{\ColWidthNormal}}
\newcolumntype{d}{>{\centering\arraybackslash\leavevmode}p{\ColWidthWide}}
% \newcolumntype{j}{@{\hspace{\ColIndentNormal}}l|} % <--- not used
\newlength{\ColWidthNormal}         \setlength{\ColWidthNormal}{1.40cm}
\newlength{\ColWidthWide}           \setlength{\ColWidthWide}{1.85cm}
\newlength{\ColIndentNormal}        \setlength{\ColIndentNormal}{6pt}
\newlength{\RuleWidthNormal}        \setlength{\RuleWidthNormal}{1.0pt}
\newlength{\RuleWidthThick}         \setlength{\RuleWidthThick}{1.5pt}

% new
\usepackage{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\newcommand\mcl[1]{\multicolumn{2}{Sl|}{#1}}

\begin{document}
    \begin{table}[!htb]
\aboverulesep=0ex
\belowrulesep=0ex
\centering
\caption{Cell colors and vertical lines OK but vertical spacing is too narrow!}
\small          % <--- changed
\begin{tabular}{S{p{0.8cm}} S{p{1.5cm}}|
    >{\bfseries}a|b |b|b |d|b
                }
\toprule[\RuleWidthThick]
\mcl{}  &       & [17]      & [12]      & [5]       & [13]         & [14]       \\
\mcl{}  &       & Moon      & Shibata   & Ali       & El-Chammas   & Ali        \\
\mcl{}  & \multirow{-3}{=}{This\\ work}
                & VLSI'17   & ISSCC'17  & VLSI'16   & ISSCC'15  & ISSCC'14      \\
\midrule[\RuleWidthNormal]
\mcl{Resolution [b]}
        & 12    & 10        & --        & 14        & 14        & 14            \\
\mcl{Technology [m]}
                    & 28n   & 28n   & 28n       & 28n       & 180n      & 65n   \\
\rowcolor{cellHighlightColor}
\mcl{Supplies [V]}  & 0.9   & 1.0   & 1.8$\pm$1.0
                                                & 2.5/1.8/0.9
                                                            & 3.3/1.8   & 3.3/2.5/1.2   \\
\mcl{Input range [V$_{pp,d}$]}
                    & 1.6   & --    & 2.0       & --        & 2.5       & 2.0   \\
\rowcolor{cellHighlightColor}
\mcl{Sampling rate [Hz]}
                    & 600   & 500M  & 9G        & 2.5G      & 500M      & 1G    \\
\mcl{ERBW [Hz]}
                    & 400M  & --    & 1.125G    & 1.5G      & 700M      & 1G    \\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor}
ENOB    & LF in.    & 9.51  & 9.1       & --        & 10.3  & 10.5      & 11.2  \\
{[b]}   & Nyquist   & 9.45  & 9.1       & 10.7      & 10    & 10.3      & 11    \\
\midrule
SNDR    & LF in.    & 59.0  & 56.7      & --        & 64    & 64.8      & 69    \\
{[dB]}  & Nyquist   & 58.7  & 56.6      & 66        & 61.7  & 64        & 68    \\
\midrule
SFDR    & LF in.    & 71.9  & 73        & 79        & 80    & 93        & 86    \\
{[dBc]} & Nyquist   & 72.4  & 69.2      & 79        & 73    & 82        & 82    \\
\midrule[\RuleWidthNormal]
\rowcolor{cellHighlightColor}
\mcl{Power [W]}     & 14.5m & 6m        & 2330m     & 1150m & 550m      & 1200m \\
\mcl{FoM$_{W}$ [J/c.-step]}
                    & 34.4f & 22f       & 715f      & 463f  & 849f      & 585f  \\
\mcl{FoM$_{S}$ [dB]}
                    & 161.9 & 162.8     & 152.3     & 152.1 & 150.6     & 154.2 \\
\rowcolor{cellHighlightColor}
\mcl{Area [mm$^{2}$]}
                    & 0.621 & 0.015     & 5.1       & 14.4  & 2.5       & 18        \\
\bottomrule[\RuleWidthThick]
\end{tabular}
    \end{table}
\end{document}

不过,我会简化您的表格设计如下(通过使用包tabularx中的规则的默认厚度booktabs

\documentclass{article}
\usepackage{newtxtext}
\usepackage{newtxmath}
% Tables
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makecell}
\usepackage[table]{xcolor}% <--- changed
\definecolor{cellHighlightColor}{rgb}{0.933333333333333   0.956862745098039   0.984313725490196}

% new
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage{cellspace}
\setlength\cellspacetoplimit{7pt}
\setlength\cellspacebottomlimit{7pt}
\newcommand\mcl[1]{\multicolumn{2}{l|}{#1}}

\begin{document}
    \begin{table}[!ht]
\aboverulesep=0ex
\belowrulesep=0ex
\centering
\caption{Cell colors and vertical lines OK but vertical spacing is too narrow!}
\small          % <--- changed
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{S{C} S{C}|
    >{\columncolor{cellHighlightColor}\bfseries}C|C |C|C |
     c|C
                }
\toprule
\mcl{}  &       & [17]      & [12]      & [5]       & [13]      & [14]          \\
\mcl{}  &       & Moon      & Shibata   & Ali       & El-Chammas    & Ali       \\
\mcl{}  & \multirow{-3}{=}{\centering   This\\ work}
                & VLSI'17   & ISSCC'17  & VLSI'16   & ISSCC'15  & ISSCC'14      \\
\midrule[\heavyrulewidth]
\mcl{Resolution [b]}
        & 12    & 10        & --        & 14        & 14        & 14            \\
\mcl{Technology [m]}
                    & 28n   & 28n   & 28n       & 28n       & 180n      & 65n   \\
\rowcolor{cellHighlightColor}
\mcl{Supplies [V]}  & 0.9   & 1.0   & 1.8$\pm$1.0
                                                & 2.5/1.8/0.9
                                                            & 3.3/1.8   & 3.3/2.5/1.2   \\
\mcl{Input range [V$_{pp,d}$]}
                    & 1.6   & --    & 2.0       & --        & 2.5       & 2.0   \\
\rowcolor{cellHighlightColor}
\mcl{Sampling rate [Hz]}
                    & 600   & 500M  & 9G        & 2.5G      & 500M      & 1G    \\
\mcl{ERBW [Hz]}
                    & 400M  & --    & 1.125G    & 1.5G      & 700M      & 1G    \\
\midrule[\heavyrulewidth]
\rowcolor{cellHighlightColor}
ENOB    & LF in.    & 9.51  & 9.1       & --        & 10.3  & 10.5      & 11.2  \\
{[b]}   & Nyquist   & 9.45  & 9.1       & 10.7      & 10    & 10.3      & 11    \\
\midrule
SNDR    & LF in.    & 59.0  & 56.7      & --        & 64    & 64.8      & 69    \\
{[dB]}  & Nyquist   & 58.7  & 56.6      & 66        & 61.7  & 64        & 68    \\
\midrule
SFDR    & LF in.    & 71.9  & 73        & 79        & 80    & 93        & 86    \\
{[dBc]} & Nyquist   & 72.4  & 69.2      & 79        & 73    & 82        & 82    \\
\midrule[\heavyrulewidth]
\rowcolor{cellHighlightColor}
\mcl{Power [W]}     & 14.5m & 6m        & 2330m     & 1150m & 550m      & 1200m \\
\mcl{FoM$_{W}$ [J/c.-step]}
                    & 34.4f & 22f       & 715f      & 463f  & 849f      & 585f  \\
\mcl{FoM$_{S}$ [dB]}
                    & 161.9 & 162.8     & 152.3     & 152.1 & 150.6     & 154.2 \\
\rowcolor{cellHighlightColor}
\mcl{Area [mm$^{2}$]}
                    & 0.621 & 0.015     & 5.1       & 14.4  & 2.5       & 18        \\
\bottomrule
\end{tabularx}
    \end{table}
\end{document}

其结果与第一个 mwe 类似:

在此处输入图片描述

相关内容