# Non-uniform row color for multi-columns + multi-rows (Partially colored rows withing merged columns and rows region)

Regarding the MWE shown below, I do not know the reason for non-uniform row color among merged columns and rows. Although I am using the command (\rowcolor{gray!25}), rows are partially colored in the region of merged columns and merged rows. I noticed that

• it is mainly the second cell in a multi-column + multi-row command that does not go along with the \rowcolor command. It causes the formatting to be inappropriate in a noticable manner.

• Also this issue apears usually (but not all the time) when using multi-row and multi-column commands at the same time,If any of those commands is used alone/seperately, row colors have no issues, but upon using them on the same group of cells, such issue arise. i.e:

\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}
{\multirow[c]{-2}{=}[0.5cm]{text}}

• Also as seen from the MWE below, some merged (rows + columns) apear normally as shown within the first 2 merged (rows + columns) within the second half of the table.

Here is the MWE:


\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,top=2.5cm,bottom=2.5cm,margin=2.5cm,bindingoffset=0.5cm]{geometry}

\makeatletter
\def\ifGm@preamble#1{%
\ifGm@newgm
%\Gm@warning{#1': not available in \string\newgeometry'; skipped}%
\expandafter\@firstofone
\else
\expandafter\@firstofone
\fi}%
\makeatother

\usepackage[bidi=basic,layout=lists.tabular]{babel}
\babelprovide[import=ar,mapdigits,main]{arabic}
\babelprovide[import=en,language=Default]{english}

\babelfont{rm}{Latin Modern Roman}
\babelfont[arabic]{rm}{amiri}
\babelfont[english]{rm}{Times New Roman}

\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{fancyhdr}
\usepackage{fancybox, graphicx}
\usepackage[table]{xcolor}
\usepackage{tabu,multirow}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{longtable}
\usepackage{array}
\newcolumntype{?}[1]{!{\vrule width #1}}
\usepackage{booktabs}
\setlength{\belowrulesep}{0pt}
\setlength{\belowbottomsep}{0pt}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\abovetopsep}{0pt}
\usepackage{makecell}
\usepackage{boldline}
\usepackage[skins,xparse,breakable]{tcolorbox}

\begin{document}

\newgeometry{landscape,margin=2.5cm}
\pagewidth  = \paperwidth
\pageheight = \paperheight

\begin{table}[htbp]
\setlength\arrayrulewidth{1pt} % so that lines apear since they get overried by rowcolors command
\begin{center}
\begin{tabular}
{
?{1mm}c
?{0.5mm}>{\centering\arraybackslash}m{2cm}
|>{\centering\arraybackslash}c
|>{\centering\arraybackslash}m{3cm}
|>{\centering\arraybackslash}m{3cm}
|>{\centering\arraybackslash}m{3cm}
|>{\centering\arraybackslash}m{2cm}?{1mm}
}
%\rowcolor{white} %Color for first row
\toprule[1mm] %may be used to draw a horizontal line at the top of the table.
%\hline % Not needed here as top rule is used
\textbf{dfdfdfdf}
&
\textbf{الحالة
dffds sdfds
}
&
\multicolumn{2}{|c|}{\textbf{tttt t ttt ttt}}
&
\textbf{rrrrr rrrrrr rrrr rrr}
&
\textbf{ttttttttttttt}
&
\textbf{ttttttt}
\\
\midrule[1mm]
\rowcolor{gray!25}
\cellcolor{white}
&

&
mm
&

&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-3}
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&

&
\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}{}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&
\multirow[c]{-2}{0cm}[0cm]
{mm}
&
\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}
{
\multirow[c]{-2}{=}[0.5cm]
{
mm
}}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\cellcolor{white}
&
\cellcolor{gray!25}
&
\foreignlanguage{coptic}{ⲩ}
&
\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}
{
mmmmmm mmmmmm mmm mmm mmm mmmmmmmm mmm mmmm mmmmmmmmm mm
}
&

mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&

&
\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}{ }
&

mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&
\multirow[c]{-2}{*}[0cm]{mm}
&
\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}
{
\multirow[c]{-2}{=}[0cm]
{
في بعض الأحيان لتعبر عن النطق الواضح
}}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\cellcolor{white}
&
\cellcolor{gray!25}
\multirow[c]{-6}{2cm}[0.5cm]
{
mmmmmm mmmmmm mmm mmm mmm mmmmmmmm
}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{
mm
}
&
mm
&
mm
&
mmmm
\\
\cmidrule[1pt]{2-7}
\rowcolor{gray!25}
\cellcolor{white}
&
\cellcolor{white}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}{ }
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&
\cellcolor{white}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{\multirow[c]{-2}{=}[0cm]{\centering mm}}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\cellcolor{white}
&

&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{mm}
&

&
mm
&
\\
\cmidrule[0.5pt]{3-4}
\cmidrule[0.5pt]{6-6}
\cellcolor{white}
&

&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}{}
&
\multirow[c]{-2}{*}[0cm]{mm}
&
mm
&
\multirow[c]{-2}{*}[0cm]{mmmm}
\\
\cmidrule[0.5pt]{5-7}
\cellcolor{white}
&

&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{\multirow[c]{-2}{=}[0cm]{\centering mm}
}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\rowcolor{gray!25}
\cellcolor{white}
\multirow[c]{-13}{*}[0.5cm]{mm}
&
\cellcolor{white}
\multirow[c]{-6}{2cm}[0.5cm]
{
mmmm mmmmm mmm mmmmmmm
}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{
mmmmmm mmmmmm mmm mmm mmm mmmmmmmm mmm
}
&
mm
&
mm
&
mmmm
\\
\bottomrule[1mm] %draws a horizontal line to finish off a table
\end{tabular}
\end{center}
\end{table}

\clearpage
\restoregeometry
\pagewidth  = \paperwidth
\pageheight = \paperheight

\end{document}



• You should have a look at {NiceTabular} of nicematrix. Aug 15, 2020 at 21:04
• It is a good suggestion, yet such package seems to have other issues such as compatibility with right to left documents among other issues that might require further attention. If you are familiar with the use of this package then I would be grateful if you can post the above table (the MWE) using this package since it seems to require some work to alter the commands and so on, also I am a bit short on time to get to master it and as you can see I am using tables with quite a lot of details (right to left, multilanguge, coloring, rules, mlticolumns,multirows,varying rule thickness...) Aug 15, 2020 at 21:59
• You are right. nicematrix would be a solution for the problems of rules and colors but it's not compatible with bidi... Aug 16, 2020 at 9:30

Well, after making several trials, You cannot ignore the width of the columns as defined in the preamble (In case you are modifying this column for the first time) and the width defined in the "multicolumn command" in comparison to other "multicolumn" commands used to modify column under considertion (In case this column was modified previously). If you match them such that the new column width exceeds the maximum defined width for the non-highlighted column a little bit, no issues will arise, else you will have the issue shown above. In short you see the maximum width used for non-highlighted column and set the new width to exceed it a little bit. So, in order to avoid confusion, see the explanation below:

• In the preamble the fourth column is defined as
"|>{\centering\arraybackslash}m{3cm}"


with column width of 3cm, while in multicolumn it is modified several times, the maximum defined width for non-highlighted column is 8cm:

\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}
{mmmmmm mmmmmm mmm mmm mmm mmmmmmmm mmm mmmm mmmmmmmmm mm}


with column width of 8cm, so the maximum defined width for non-highlighted column is 8 cm. Set the new column width to at least 9 cm in the highlited rows.

\multicolumn{1}{|>{\centering\arraybackslash}m{9cm}|}{ }



\multicolumn{1}{|>{\centering\arraybackslash}m{9cm}|}{\multirow[c]{-2}{=}[0cm]{في بعض الأحيان لتعبر عن النطق الواضح}}


The final MWE is shown below:


\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,top=2.5cm,bottom=2.5cm,margin=2.5cm,bindingoffset=0.5cm]{geometry}

\makeatletter
\def\ifGm@preamble#1{%
\ifGm@newgm
%\Gm@warning{#1': not available in \string\newgeometry'; skipped}%
\expandafter\@firstofone
\else
\expandafter\@firstofone
\fi}%
\makeatother

\usepackage[bidi=basic,layout=lists.tabular]{babel}
\babelprovide[import=ar,mapdigits,main]{arabic}
\babelprovide[import=en,language=Default]{english}

\babelfont{rm}{Latin Modern Roman}
\babelfont[arabic]{rm}{amiri}
\babelfont[english]{rm}{Times New Roman}

\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{fancyhdr}
\usepackage{fancybox, graphicx}
\usepackage[table]{xcolor}
\usepackage{tabu,multirow}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{longtable}
\usepackage{array}
\newcolumntype{?}[1]{!{\vrule width #1}}
\usepackage{booktabs}
\setlength{\belowrulesep}{0pt}
\setlength{\belowbottomsep}{0pt}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\setlength{\abovetopsep}{0pt}
\usepackage{makecell}
\usepackage{boldline}
\usepackage[skins,xparse,breakable]{tcolorbox}

\begin{document}

\newgeometry{landscape,margin=2.5cm}
\pagewidth  = \paperwidth
\pageheight = \paperheight

\begin{table}[htbp]
\setlength\arrayrulewidth{1pt} % so that lines apear since they get overried by rowcolors command
\begin{center}
\begin{tabular}
{
?{1mm}c
?{0.5mm}>{\centering\arraybackslash}m{2cm}
|>{\centering\arraybackslash}c
|>{\centering\arraybackslash}m{3cm}
|>{\centering\arraybackslash}m{3cm}
|>{\centering\arraybackslash}m{3cm}
|>{\centering\arraybackslash}m{2cm}?{1mm}
}
%\rowcolor{white} %Color for first row
\toprule[1mm] %may be used to draw a horizontal line at the top of the table.
%\hline % Not needed here as top rule is used
\textbf{dfdfdfdf}
&
\textbf{الحالة
dffds sdfds
}
&
\multicolumn{2}{|c|}{\textbf{tttt t ttt ttt}}
&
\textbf{rrrrr rrrrrr rrrr rrr}
&
\textbf{ttttttttttttt}
&
\textbf{ttttttt}
\\
\midrule[1mm]
\rowcolor{gray!25}
\cellcolor{white}
&

&
mm
&
\multicolumn{1}{|>{\centering\arraybackslash}m{9cm}|}{}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-3}
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&

&
\multicolumn{1}{|>{\centering\arraybackslash}m{9cm}|}{}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&
\multirow[c]{-2}{0cm}[0cm]
{mm}
&
\multicolumn{1}{|>{\centering\arraybackslash}m{9cm}|}
{
\multirow[c]{-2}{=}[0.5cm]
{
mm
}}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\cellcolor{white}
&
\cellcolor{gray!25}
&
\foreignlanguage{coptic}{ⲩ}
&
\multicolumn{1}{|>{\centering\arraybackslash}m{8cm}|}
{
mmmmmm mmmmmm mmm mmm mmm mmmmmmmm mmm mmmm mmmmmmmmm mm
}
&

mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&

&
\multicolumn{1}{|>{\centering\arraybackslash}m{9cm}|}{ }
&

mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&

&
\multirow[c]{-2}{*}[0cm]{mm}
&
\multicolumn{1}{|>{\centering\arraybackslash}m{9cm}|}
{
\multirow[c]{-2}{=}[0cm]
{
في بعض الأحيان لتعبر عن النطق الواضح
}}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\cellcolor{white}
&
\cellcolor{gray!25}
\multirow[c]{-6}{2cm}[0.5cm]
{
mmmmmm mmmmmm mmm mmm mmm mmmmmmmm
}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{
mm
}
&
mm
&
mm
&
mmmm
\\
\cmidrule[1pt]{2-7}
\rowcolor{gray!25}
\cellcolor{white}
&
\cellcolor{white}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}{ }
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{5-7}
\rowcolor{gray!25}
\cellcolor{white}
&
\cellcolor{white}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{\multirow[c]{-2}{=}[0cm]{\centering mm}}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\cellcolor{white}
&

&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{mm}
&

&
mm
&
\\
\cmidrule[0.5pt]{3-4}
\cmidrule[0.5pt]{6-6}
\cellcolor{white}
&

&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}{}
&
\multirow[c]{-2}{*}[0cm]{mm}
&
mm
&
\multirow[c]{-2}{*}[0cm]{mmmm}
\\
\cmidrule[0.5pt]{5-7}
\cellcolor{white}
&

&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{\multirow[c]{-2}{=}[0cm]{\centering mm}
}
&
mm
&
mm
&
mmmm
\\
\cmidrule[0.5pt]{3-7}
\rowcolor{gray!25}
\cellcolor{white}
\multirow[c]{-13}{*}[0.5cm]{mm}
&
\cellcolor{white}
\multirow[c]{-6}{2cm}[0.5cm]
{
mmmm mmmmm mmm mmmmmmm
}
&
\multicolumn{2}{|>{\centering\arraybackslash}m{10cm}|}
{
mmmmmm mmmmmm mmm mmm mmm mmmmmmmm mmm
}
&
mm
&
mm
&
mmmm
\\
\bottomrule[1mm] %draws a horizontal line to finish off a table
\end{tabular}
\end{center}
\end{table}

\clearpage
\restoregeometry
\pagewidth  = \paperwidth
\pageheight = \paperheight
`