1

I am creating a color table, and I tried using multirowcell. However this seems to mess with the background color, as you can see in the picture below. How can I fix that using multirowcell?

enter image description here

The code:

\begin{table}[H]
\centering
\renewcommand{\arraystretch}{1.5}
\rowcolors{2}{MidnightBlue!10}{white}
\begingroup\setlength{\fboxsep}{0pt}
 \colorbox{MidnightBlue!30}{%
\begin{tabular}{|c|c|c|c|c|} 
\hline
\rowcolor{MidnightBlue!30} & \multicolumn{2}{c|}{\textbf{test1}} & \multicolumn{2}{l|}{\textbf{test2}} \\ 
 \hhline{|~|-|-|-|-|}
\rowcolor{MidnightBlue!30} & & & & \\
\rowcolor{MidnightBlue!30} \multirow{-3}{*}{test3} & \multirow{-2}{*}{\shortstack{test1\\test}} & \multirow{-2}{*}{\shortstack{test2\\test}}  & \multirow{-2}{*}{\shortstack{test1\\test}} & \multirow{-2}{*}{\shortstack{test2\\test}} \\
\hline 
\rowcolor{white}& & & & \\
\multirowcell{-2}{test \\ test} & \multirowcell{-2}{test} & \multirowcell{-2}{test} & \multirowcell{-2}{test} & \multirowcell{-2}{test} \\
test & test & test & test & test \\
\hhline{|-|-|-|-|-|}
\end{tabular}%
}\endgroup
\caption{\textbf{test}}
\end{table}

2 Answers 2

2

With {NiceTabular} of nicematrix, you won't have that kind of problem.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{float}
\usepackage{nicematrix}

\begin{document}

\begin{table}[H]
\centering
\renewcommand{\arraystretch}{1.5}
\begin{NiceTabular}{ccccc}[vlines]
\CodeBefore
    \rowcolor{MidnightBlue!30}{1,2,3}
    \rowcolors{4}{MidnightBlue!10}{}[respect-blocks]
\Body
    \hline
    \Block{3-1}{text3} & \Block{1-2}{\textbf{test1}} && \Block{1-2}{\textbf{test2}} \\ 
    \Hline
    & \Block{2-1}{test1\\test} & \Block{2-1}{test2\\test}  & \Block{2-1}{test1\\test} & \Block{2-1}{test2\\test} \\ \\
    \hline 
    \Block{2-1}{test\\ test} & test & test & test & test \\ \\
    test & test & test & test & test \\
    \hline
\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

Instead of a \colorbox and \rowcolor{white}, I suggest using an\hhline which has the background colour in the first column:

\documentclass{article}

\usepackage{caption, float}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{multirow, hhline}
\usepackage{makecell}

\begin{document}

\begin{table}[H]
\centering
\renewcommand{\arraystretch}{1.5}
\rowcolors{2}{MidnightBlue!10}{white}
\begin{tabular}{|c|c|c|c|c|}
\hline
\rowcolor{MidnightBlue!30} & \multicolumn{2}{c|}{\textbf{test1}} & \multicolumn{2}{l|}{\textbf{test2}} \\[-0.4pt]
 \hhline{|>{\arrayrulecolor{MidnightBlue!30}}->{\arrayrulecolor{black}}|-|-|-|-|}
\rowcolor{MidnightBlue!30} & & & & \\[-0.4pt]
\rowcolor{MidnightBlue!30} \multirow{-3}{*}{test3} & \multirow{-2}{*}{\shortstack{test1\\test}} & \multirow{-2}{*}{\shortstack{test2\\test}} & \multirow{-2}{*}{\shortstack{test1\\test}} & \multirow{-2}{*}{\shortstack{test2\\test}} \\
\hline
\rowcolor{white}& & & & \\
\multirowcell{-2}{test \\ test} & \multirowcell{-2}{test} & \multirowcell{-2}{test} & \multirowcell{-2}{test} & \multirowcell{-2}{test} \\
test & test & test & test & test \\
\hhline{|-|-|-|-|-|}
\end{tabular}%
\caption{\textbf{test}}
\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 .