单元格颜色未填满所有单元格

单元格颜色未填满所有单元格

我想填充单元格“物理徽章”,但是当我使用时\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 节点)。

上述代码的输出

相关内容