1

Edit: Apparently, I wasn't very clear on what I wanted. What I wanted to do is alternate the Grey and White colors between the rows. In this case, the first line (the header) should be Grey. With the \multirow, this was not possible without the color covering the text, as you can see with header 4 and header 5.

The \multirow text is covered by the background color. Does someone know why and how can I fix it? I already tried to add '-' in \multirow{-2}{*}{ \textbf{header1}} as you can see below, but still didn't work for me.

test table

 \usepackage{multirow}
 \usepackage{graphicx}
\begin{table}[t]
\centering
\scriptsize
\begin{tabular}{p{1.7 cm}|p{1.4cm}|p{1.9cm}|p{1.5cm}|p{1.1cm}|p{2.1cm}|p{1.55cm}|p{1.2cm}|p{1.4cm}}
\toprule
\rowcolor{Gainsboro!60}
 \multirow{-2}{*}{ \textbf{header1}} &
  \multicolumn{4}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}header2 \end{tabular}}} &
  \multicolumn{2}{c|}{\textbf{\begin{tabular}[c]{@{}c@{}}header 3.1 \\ \& header 3.2\end{tabular}}} &
   \multirow{2}{*}{\textbf{\begin{tabular}[l]{@{}l@{}}header \\ 4\end{tabular}}} &
  \multirow{2}{*}{\textbf{\begin{tabular}[l]{@{}l@{}}header \\ 5\end{tabular}}} \\
  \cline{2-7} 
  \rowcolor{Gainsboro!60}
 &
  \textbf{A} &
  \textbf{B} &
  \textbf{\begin{tabular}[l]{@{}l@{}}C\end{tabular}}&
  \textbf{D} &
  \textbf{\begin{tabular}[l]{@{}l@{}}E \end{tabular}} &
  \textbf{\begin{tabular}[l]{@{}l@{}}F\\ \end{tabular}}
  &   &  
   \\ \hline
\citet{Jung2014} &
 aaa &
  \begin{tabular}[l]{@{}l@{}}bbb\\ ccc\end{tabular} &
   &
  eee &
  fff &
  - &
  \_ &
  X \\ \hline
  \rowcolor{Gainsboro!60}
  \citet{CAO2020998} &
 aaa &
  \begin{tabular}[l]{@{}l@{}}bbb\\ ccc\\  ddd\\ kkk\end{tabular} &
   &
  eee &
  fff &
  ttt &
  \_ &
  X \\ 
  \bottomrule
\end{tabular}%

\caption[Caption for LOF]{Comparison Table of Usage Control Policies \protect\footnotemark}
\label{tab:specification}
\end{table} 
6
  • 1
    As always on this site you are much more likely to get any help if you provide a full but minimal example others can just copy and test. We have to add stuff in order to test your sniplet
    – daleif
    Jul 13, 2021 at 14:55
  • You can add \cellcolor{white} to your multirow. This being said I would remove the vertical padding of \toprule and \bottomrule to delete the upper and lower white strips, which don't look very good.
    – Bernard
    Jul 13, 2021 at 15:19
  • @daleif Thank you for your comment. I just added now the packages that I forgot to add before. Thank you for the advice.
    – Ines
    Jul 13, 2021 at 15:50
  • @Bernard. Thank you for your reply. Could you please elaborate more on how \cellcolor{white} would fix my problem ? Where exactly should I add \cellcolor{white} ?
    – Ines
    Jul 13, 2021 at 15:52
  • Please be so kind and extend you code fragment to complete small document beginning with ˙\|documentclass{...} followed by loading all packages needed to compile it, your code fragment with end by `\end{document}. This document, called MWE (Minimal Working Example) test yourself first and than upload in your question. Please make more clear, what is your problem. Should be text in multirow cell only visible or should be cell background white?
    – Zarko
    Jul 13, 2021 at 16:01

2 Answers 2

3

I guess that you are after this:

enter image description here

(red lines indicate top part of page layout)

With new table package tabularray which is based on LaTeX3, the MWE with your table can be:

\documentclass{article}
\usepackage{geometry}
\usepackage[table, svgnames]{xcolor}
\usepackage{tabularray}
\usepackage{natbib}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[ht]
    \centering
    \small
\begin{tblr}{width=\linewidth,
             colspec = {X[1,l,m]X[1,l,m] X[1,l,m]X[1,l,m] X[1,l,m]X[1,l,m] X[1,l,m]X[1,l,m] X[1,l,m]},
             hlines,   vlines,
             hline{1,5}={1.2pt},
             hline{3}={0.8pt},
             colsep=4pt,
             row{even} = {bg=Gainsboro!60},
             row{1}   = {bg=Gainsboro!60,font=\bfseries},
             row{2}   = {font=\bfseries},
             rowsep=1pt,
             }
header1
    &   \multicolumn{4}{c}{header2}
        &   \multicolumn{2}{c}{{header 3.1 \\ \& header 3.2}}
            &   \multirow{2}{=}{header 4}
                &   \multirow{2}{=}{header 5}   \\
    & A & B & C & D & E & F &   &               \\
\citet{Jung2014}
    &   aaa
        &   {bbb\\ ccc}
            &   &   eee
                    &   fff
                        &   -
                            &   \_
                                &   X           \\
\citet{CAO2020998}
    &   aaa
        &   {bbb\\ ccc\\  ddd\\ kkk}
            &   &   eee
                    &   fff
                        &   ttt &   \_
                                    &   X       \\
\end{tblr}%

\caption[Caption for LOF]{Comparison Table of Usage Control Policies \protect\footnotemark}
\label{tab:specification}
    \end{table}
\end{document}
7
  • It may be simpler to write {r=2} instead of {r=2,c=1}.
    – L.J.R.
    Jul 14, 2021 at 1:16
  • @L.J.R., you are right. Corected. I still learn this nice package, and some approach is still rude or are based on extrapolation of showed examples in documentation. So all my answers are also exercises for me ;-).
    – Zarko
    Jul 14, 2021 at 1:39
  • @Zarko Thank you very much for your reply. Apparently I wasn't very clear with what I wanted. I wanted to alternate colors Grey and White between rows, so the header would be Grey (including header 1). I can see from your code that I only need to remove cell{1}{1} = {r=2}{l,white} to get the results I need. I will try that for now. Another question as I'm not really familiar with using Tabular array. In your code, you didn't specify the size of the columns, right? Do you have any specific links for documentation where they describe this package ? Thanks again!
    – Ines
    Jul 14, 2021 at 11:22
  • @Ines, you right, your question is not clear at all. I correct my answer, but similar result gives your code fragment in question. What exactly is your problem? Please, consider all comments below question and edit your question do what you asked for in them.
    – Zarko
    Jul 14, 2021 at 13:25
  • @Ines, any news? If edited answer gives what you like to have, you should consider to accept them (by clicking on check mark at the top left side of answer),
    – Zarko
    Jul 16, 2021 at 6:12
1

The environment {NiceTabular} of nicematrix provides a command a built-in command \rowcolors for coloring rows with alterning colors.

That command has a key respect-blocks. With that key, the blocks (created by the command \Block will be respected). That means that you will have an alternance of colors for the logical rows (rather than for the physical rows of the tabular).

\documentclass{article}
\usepackage{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{nicematrix,booktabs}

\begin{document}

\begin{table}[ht]
\centering
\small
\begin{NiceTabular}
   [hvlines-except-borders,cell-space-limits=1mm,color-inside]
   {*{9}{X[l,m]}}
\toprule
\rowcolors{Gainsboro!60}{}[respect-blocks]
\RowStyle[nb-rows=2]{\bfseries}
\Block{2-1}{header1}
    &   \Block{1-4}{header2}&&&
        &   \Block{1-2}{header 3.1 \\ \& header 3.2}
            &&   \Block{2-1}{header 4}
                &   \Block{2-1}{header 5}   \\
    & A & B & C & D & E & F &   &               \\
?
    &   aaa
        &   \Block{}{bbb\\ ccc}
            &   &   eee
                    &   fff
                        &   -
                            &   \_
                                &   X           \\
?
    &   aaa
        &   \Block{}{bbb\\ ccc\\  ddd\\ kkk}
            &   &   eee
                    &   fff
                        &   ttt &   \_
                                    &   X       \\
\bottomrule
\end{NiceTabular}

\caption[Caption for LOF]{Comparison Table of Usage Control Policies \protect\footnotemark}
\label{tab:specification}
\end{table}

\end{document}

However, you need several compilations.

Output of the above code

You must log in to answer this question.

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