![单元格颜色未填满所有单元格](https://linux22.com/image/463247/%E5%8D%95%E5%85%83%E6%A0%BC%E9%A2%9C%E8%89%B2%E6%9C%AA%E5%A1%AB%E6%BB%A1%E6%89%80%E6%9C%89%E5%8D%95%E5%85%83%E6%A0%BC.png)
我想填充单元格“物理徽章”,但是当我使用时\cellcolor
,右侧会出现一个白色矩形。我不明白为什么。代码如下:
\begin{tabular}{|c|c|c|c|c|c|}
\hline
&\cellcolor{darkgray!95}\color{white} provider & \cellcolor{darkgray!95}\color{white} timing & \cellcolor{darkgray!95}\color{white}friction &\cellcolor{darkgray!95}\color{white} resilience & \cellcolor{darkgray!95}\color{white}\makecell{infrastructure\\requirement}\\ \hline
\cellcolor{lightgray}\textbf{\makecell{manual \\ completion}} & \makecell{worker or \\ employer} & async & high & low & low \\ \hline
\cellcolor{lightgray}\textbf{\makecell{physical\\badging} }& worker & sync & mid & mid to high & mid to high\\ \hline
\cellcolor{lightgray}\textbf{digital log}& worker & sync & low to mid & mid & low to mid \\ \hline
\cellcolor{lightgray}\textbf{\makecell{geofencing\\-\\smart\\contact\\tracing}}& process & sync & low & high & low to mid \\ \hline
\end{tabular}
输出为:
答案1
p{}
如果您指定具有明确宽度的列类型,则以下示例有效:
\documentclass{article}
\usepackage{geometry}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{colortbl}
\newcolumntype{P}{>{\centering}p{2.5cm}}
\renewcommand\cellalign{{}{P}}
\begin{document}
\begin{table}[tbh]
\centering
\begin{tabular}{| >{\columncolor{lightgray}}c| *5{c|}}
\hline
\rowcolor{darkgray!95}\cellcolor{white}
& \color{white}provider
& \color{white}timing
& \color{white}friction
& \color{white}resilience
& \color{white}\makecell{infrastructure\\requirement} \\
\hline
\textbf{\makecell{manual\\completion}}
& \makecell{worker or\\employer}
& async
& high
& low
& low \\
\hline
\textbf{\makecell{physical\\badging}}
& worker
& sync
& mid
& mid to high
& mid to high \\
\hline
\textbf{\makecell{digital\\log}}
& worker
& sync
& low to mid
& mid
& low to mid \\
\hline
\textbf{\makecell{geofencing\\-\\smart\\contact\\tracing}}
& process
& sync
& low
& high
& low to mid \\
\hline
\end{tabular}
\end{table}
\end{document}
答案2
{NiceTabular}
供参考,这里有一种使用来创建表格的方法nicematrix
。
\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{nicematrix}
\begin{document}
\begin{table}[tbh]
\centering
\begin{NiceTabular}{>{\bfseries}c*5{c}}[hvlines,cell-space-limits=4pt]
\CodeBefore
\rectanglecolor{darkgray!95}{1-2}{1-*}
\rectanglecolor{lightgray}{2-1}{*-1}
\Body
\RowStyle[color=white]{\sffamily}
& provider
& timing
& friction
& resilience
& \Block{}{infrastructure\\requirement} \\
\Block{}{manual\\completion}
& \Block{}{worker or\\employer}
& async
& high
& low
& low \\
\Block{}{physical\\badging}
& worker
& sync
& mid
& mid to high
& mid to high \\
\Block{}{digital\\log}
& worker
& sync
& low to mid
& mid
& low to mid \\
\Block{}{geofencing\\-\\smart\\contact\\tracing}
& process
& sync
& low
& high
& low to mid \\
\end{NiceTabular}
\end{table}
\end{document}
您需要进行多次编译(因为nicematrix
在后台使用了 PGF/TikZ 节点)。