表格中彩色单元格重叠的水平线

表格中彩色单元格重叠的水平线

在将颜色应用于单元格后,我无法看到水平线。此外,“故障清除后”文本似乎没有垂直居中。以下是我的问题示例:

\documentclass[10pt,a5paper,twoside,openright]{book}
\usepackage{booktabs,multicol,multirow,bigstrut}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\usepackage{array}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\def\tabularxcolumn#1{m{#1}}

\begin{document}

\begin{table}[htbp]
\setlength\belowcaptionskip{5pt}
\scriptsize
\centering
\caption{ACR Status}
  \begin{tabularx}{\linewidth}{|c|c|Y|Y|Y|}
\hline
\cellcolor{blue!30}  &\cellcolor{blue!30} 
& \multicolumn{3}{c|}  {\cellcolor{blue!30}\textbf{Status}} \bigstrut[b]\\            
\cline{3-5} \multirow{-2}[0]{*}{\cellcolor{blue!30} \textbf{No.}} 
& \multirow{-2}[0]{*}{\cellcolor{blue!30} \textbf{ACR}} 
& \cellcolor{blue!30} \textbf{Before Fault}
& \cellcolor{blue!30}\textbf{During  Fault} 
& \cellcolor{blue!30}\textbf{After Fault Clearance} \bigstrut[b]\\
    \hline
    1     & ACR1  & 1     & 0     & 1 \bigstrut[b]\\
    \hline
    2     & ACR2  & 1     & 0     & 1 \bigstrut\\
    \hline
    3     & ACR3  & 0     & 1     & 0 \bigstrut\\
    \hline
    4     & ACR4  & 1     & 1     & 1 \bigstrut\\
    \hline
    5     & ACR5  & 1     & 1     & 1 \bigstrut[t]\\
    \hline
    \end{tabularx}%
\end{table}%

\end{document}

答案1

这是一个{NiceTabular}使用 的解决方案nicematrix

在 中{NiceTabular},您可以使用命令 水平和垂直合并单元格\Block。对于行,您可以给出逻辑行数(而不是像 那样给出物理行数\multirow)。然后,该键hvlines将绘制除块之外的所有规则。

\documentclass[10pt,a5paper,twoside,openright]{book}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{nicematrix}

\begin{document}

\begin{table}[htbp]\centering
\caption{ACR Status}
\scriptsize
\begin{NiceTabular}{cc*3{X[c,m]}}[hvlines,cell-space-limits=3pt]
  \RowStyle[nb-rows=2,rowcolor=blue!30]{\bfseries}
  \Block{2-1}{No.} &\Block{2-1}{ACR} & \Block{1-3}{Status}\\ 
  & & Before Fault & During  Fault & After Fault Clearance\\
  1 & ACR1  & 1 & 0 & 1 \\
  2 & ACR2  & 1 & 0 & 1 \\
  3 & ACR3  & 0 & 1 & 0 \\
  4 & ACR4  & 1 & 1 & 1 \\
  5 & ACR5  & 1 & 1 & 1 \\
\end{NiceTabular}
\end{table}

\end{document}

您需要进行多次编译(因为nicematrix在后台使用了 PGF/TikZ 节点)。

上述代码的输出

答案2

解决方案如下tabularray

\documentclass[10pt,a5paper,twoside,openright]{book}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{caption}
\begin{document}
\begin{table}[htbp]\centering
\caption{ACR Status}
\begin{tblr}{
  width={\linewidth}, 
  colspec={*2{Q[c,m]}*3{X[c,m]}}, 
  vspan=even,
  hlines, vlines,
  rows={font=\scriptsize},
  row{1,2}={bg={blue!30}, font=\scriptsize\bfseries},
  }
  \SetCell[r=2]{c} No. &\SetCell[r=2]{c} ACR & \SetCell[c=3]{c} Status&&\\            
  & & Before Fault & During  Fault & After Fault Clearance\\
  1 & ACR1  & 1 & 0 & 1 \\
  2 & ACR2  & 1 & 0 & 1 \\
  3 & ACR3  & 0 & 1 & 0 \\
  4 & ACR4  & 1 & 1 & 1 \\
  5 & ACR5  & 1 & 1 & 1 \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

相关内容