答案1
和 都会\toprule
增加\midrule
一些垂直空间,因此\rowcolor
无法完全填充明显的单元格空间,但您可以使用来\specialrule
制作特别指定规则:
\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{booktabs,tabularx}
\renewcommand\toprule{\specialrule{1pt}{1pt}{0pt}\rowcolor{gray!10}}
\renewcommand\midrule{\specialrule{0.4pt}{0pt}{0pt}}
\begin{document}
\renewcommand\arraystretch{1.4}\tabcolsep3pt
\begin{tabularx}{\linewidth}{p{6em}XXXXXXXXXXX}
\toprule
\rowcolor{gray!10}
Typeface\par \verb|\selectfont| &
Bold\par \verb|b| &
Semibold\par \verb|sb|&
Medium\par \verb|mb|&
Text\par \verb|tx|&
Regular\par \verb|m|&
Light\par \verb|l|&
Extra L\par \verb|el|&
Thin\par \verb|t|\\
\midrule
Plex Serif & Words & Words & Words & Words
& Words & Words & Words & Words \\
Plex Sans & \sffamily Words & Words & Words
& Words & Words & Words & Words & Words\\
\bottomrule
\end{tabularx}
\end{document}
答案2
这是一个使用的解决方案卡路里。 自从卡路里单元格命令在关闭之前一直有效,因此很容易为行着色。只需使用\gray
我使用的定义定义您需要的每种颜色的命令即可。在您想要灰色的第一个单元格之前打开\gray
(或您定义的任何其他颜色),并在您想要正常背景时将其关闭(相同的命令)。
使用背景颜色来强调行,和toprule
是midrule
不必要的(我在这里没有关闭它们)。我的表格看起来不同,因为我没有使用不同粗细的 Plex Serif 和 Plex Sans。
为了避免第二行标题不对齐,我已\vfil
在单元格中明确将其对齐。此外,我已加载包逐字框允许在单元格中使用 verbatimematerial。
\documentclass[a4paper]{article}
\usepackage{cals, xcolor}
\usepackage{verbatimbox}
\usepackage[margin=2.5cm]{geometry}
\newsavebox\myVerb
\newcommand*{\verbBox}{\usebox\myVerb}
\let\nc=\nullcell % Shortcuts
\let\sc=\spancontent
\begin{document}
\begin{calstable}
\begin{verbbox}[\footnotesize]
\selectfont
\end{verbbox}
% Defining 3 column relativ to each other and relativ to the margins
\colwidths{{\dimexpr(\columnwidth)/90*12\relax}
{\dimexpr(\columnwidth)/90*9\relax}
{\dimexpr(\columnwidth)/90*11\relax}
{\dimexpr(\columnwidth)/90*10\relax}
{\dimexpr(\columnwidth)/90*10\relax}
{\dimexpr(\columnwidth)/90*10\relax}
{\dimexpr(\columnwidth)/90*10\relax}
{\dimexpr(\columnwidth)/90*10\relax}
{\dimexpr(\columnwidth)/90*8\relax}
}
% The tabular fills the text area
% Set up the tabular
\makeatletter
\def\cals@framers@width{0.4pt} % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0pt}
\def\cals@bodyrs@width{0.4pt}
\cals@setpadding{Ag}
\cals@setcellprevdepth{Al}
\def\cals@cs@width{0.4pt} % Inside rules, reduce if the rule is too heavy
\def\cals@rs@width{0.4pt}
\def\cals@bgcolor{}
\def\gray{\ifx\cals@bgcolor\empty
\def\cals@bgcolor{gray!30}
\else \def\cals@bgcolor{} \fi}
\def\tb{\ifx\cals@borderT\relax % Top border switch (off-on)
\def\cals@borderT{0pt}
\else \let\cals@borderT\relax\fi}
\def\bb{\ifx\cals@borderB\relax % Botton border switch (off-on)
\def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}
\def\rb{\ifx\cals@borderR\relax % Right border switch (off-on)
\def\cals@borderR{0pt}
\else \let\cals@borderR\relax\fi}
\def\lb{\ifx\cals@borderL\relax % Left border switch (off-on)
\def\cals@borderL{0pt}
\else \let\cals@borderL\relax\fi}
% R1
\thead{
\brow
\gray\bb\lb\rb\cell{Typeface}
\cell{Bold}
\cell{Semibold}
\cell{Medium}
\cell{Text}
\cell{Regular}
\cell{Light}
\cell{Extra L}
\cell{Thin}\bb
\erow
% R2 Body
\brow
\ttfamily\footnotesize\cell{\vfil\theverbbox}
\cell{\vfil b}
\cell{\vfil sb}
\cell{\vfil mb}
\cell{\vfil tx}
\cell{\vfil m}
\cell{\vfil l}
\cell{\vfil el}
\cell{\vfil t}\rmfamily\small\gray
\erow
}
% R3 Body
\brow
\bb\cell{Plex Serif}
\cell{\bfseries Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\erow
% R4 Body
\brow
\itshape\cell{Plex Serif}
\cell{\bfseries Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\normalfont
\erow
% R5 Body
\brow
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\cell{}
\erow
% R6 Body
\brow
\sffamily\cell{Plex Sans}
\cell{\bfseries Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\erow
% R7 Body
\brow
\itshape\cell{ Plex Sans}
\cell{\bfseries Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}
\cell{Word}\normalfont
\erow
\makeatletter
\end{calstable}\par % \par needed to align the tabular
\end{document}
答案3
环境{NiceTabular}
具有nicematrix
以与之兼容的方式为单元格、行和列着色的工具booktabs
。
\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}
\begin{document}
\begin{NiceTabular}{cc}
\CodeBefore
\rowcolor{gray!20}{1,2}
\Body
\toprule
Typeface & Bold \\
\verb|\selectfont| & b \\
\midrule
Plex Serif & \textbf{Words} \\
\bottomrule
\end{NiceTabular}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。