有没有办法让数组包垂直挤压,而不是扩展行?
以下是 MWE:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{lll}
\toprule
Time & Money & Length \\
\midrule
\rowcolor{yellow} Contemporary \\
Sec & \$ & inch\\
Hour & cents & cm \\
\midrule
\rowcolor{yellow} Ancient \\
? & Dinar & Yard \\
horae & Drachma & Palm \\
\bottomrule
\end{tabular}
\end{document}
我的输出是:
我试图让黄色矩形接触\midrule
其上方,
没有使线路高度高于必要水平。
** 编辑 **
请注意,当我使用时问题就消失了\hline
,但是,我真的很喜欢的专业外观\midrule
,我宁愿不自己模仿它。
答案1
您可以在第一步中删除由包确定的规则周围的垂直空格booktabs
,然后在第二步使用包向单元格添加垂直空格cellspace
:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs, cellspace}
\setlength\abovetopsep{0pt}
\setlength\belowrulesep{0pt}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\begin{document}
\begin{tabular}{Slll}
\toprule
Time & Money & Length \\
\midrule
\rowcolor{yellow} Contemporary \\
Sec & \$ & inch\\
Hour & cents & cm \\
\midrule
\rowcolor{yellow} Ancient \\
? & Dinar & Yard \\
horae & Drachma & Palm \\
\bottomrule
\end{tabular}
\end{document}
答案2
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\setlength{\belowrulesep}{0pt}% distance below booktabs rules (not \bottomrule)
\setlength{\aboverulesep}{0pt}% distance above booktabs rules (not \toprule)
\begin{document}
\begin{tabular}{lll}
\toprule
Time & Money & Length \\
\midrule
\rowcolor{yellow} Contemporary \\
Sec & \$ & inch\\
Hour & cents & cm \\
\midrule
\rowcolor{yellow} Ancient \\
? & Dinar & Yard \\
horae & Drachma & Palm \\
\bottomrule
\end{tabular}
\end{document}
但请注意,这完全违背了booktabs
哲学!所以你也可以使用:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{array}
\begin{document}
\begin{tabular}{lll}
\firsthline
Time & Money & Length \\
\hline
\rowcolor{yellow} Contemporary \\
Sec & \$ & inch\\
Hour & cents & cm \\
\hline
\rowcolor{yellow} Ancient \\
? & Dinar & Yard \\
horae & Drachma & Palm \\
\lasthline
\end{tabular}
\end{document}
答案3
您可以使用\specialrule
:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\newcommand{\yellowbox}[1]{%
\specialrule{\lightrulewidth}{\aboverulesep}{0pt}
\hspace*{-\tabcolsep}%
\begingroup
\setlength{\fboxsep}{0pt}%
\colorbox{yellow}{\hspace{\tabcolsep}\strut #1\hspace{\tabcolsep}}%
\endgroup
\hspace*{-\tabcolsep}%
}
\begin{document}
\begin{tabular}{lll}
\toprule
Time & Money & Length \\
\yellowbox{Contemporary} \\
Sec & \$ & inch \\
Hour & cents & cm \\
\yellowbox{Ancient} \\
? & Dinar & Yard \\
horae & Drachma & Palm \\
\bottomrule
\end{tabular}
\bigskip
\begin{tabular}{lll}
\toprule
Time & Money & Length \\
\midrule
\emph{Contemporary} \\
Sec & \$ & inch \\
Hour & cents & cm \\
\midrule
\emph{Ancient} \\
? & Dinar & Yard \\
horae & Drachma & Palm \\
\bottomrule
\end{tabular}
\end{document}
我提供了该表的两个副本,后者是我更想要的。