2

I am unable to get a horizontal line visible after I have applied color to the cells. Also, the text "After Fault Clearance" doesn't seem to be vertically centered. Below is a sample of my problem:

\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}
4
  • 1
    as documented in the colortbl documentation the colour panels will always overlap \cline you could use \hhline from the package of the same name, instead. Commented Oct 7, 2015 at 7:00
  • In my working example above, I am not using the colortbl package. Is this really necessary? If yes, I'm not sure how to go about it also.
    – pyro
    Commented Oct 7, 2015 at 7:21
  • @pyro Yes you are. \usepackage[table]{xcolor} will load colortbl. Commented Oct 7, 2015 at 7:28
  • I see...tq for pointing that out. Still figuring out how to work this out. My skills are not up to mark unfortunately.
    – pyro
    Commented Oct 7, 2015 at 8:02

2 Answers 2

2

Here is a solution with {NiceTabular} of nicematrix.

In {NiceTabular}, you merge cells both horizontally and vertically with the command \Block. For the rows, you give the number of logical rows (and not the number of physical lines as with \multirow). Then the key hvlines will draw all the rules, except in the blocks.

\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}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

Output of the above code

1

A solution with 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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .