1

I had some tables with alternating row coloring, using \rowcolors{1}{white}{gray} and tabular environment. After that, I wanted to reset my rowcolors to the default, so I did \rowcolors{1}{white}{white}. However, when I tried to use multirow, I still had the problem with the overlapping background. I know that I can use a negative index, as in an alternating colored table, but my question is, how can I reset colors to default?

When I have a clean latex document, I can use multirow without negative indexes. Can I somehow get back to that after I used rowcolors command?

\rowcolors{1}{white}{gray}

**tables and other code**

\begin{table}[H]
\renewcommand{\arraystretch}{1.5}
\rowcolors{1}{white}{white}
\begin{center}
\begin{tabular}{ | c | c | c | c | c | }
\hline
\multirow{2}{*}{teeeeeeeeest} & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1\\
\hline
& 1 & 1 & 1 & 1\\
\hline
\end{tabular}
\end{center}
\end{table}

The result:

enter image description here

1

With {NiceTabular} of nicematrix, we have the possibility to fix exactly the scope of your command \rowcolors. You have also a command \Block which is easy to use everywhere to replace \multicolumn and \multirow (however, those commands are still available if you want).

\documentclass{article}
\usepackage{nicematrix}
\usepackage{xcolor}

\begin{document}

\begin{NiceTabular}{cc}[hvlines,code-before = \rowcolors{4-10}{red!15}{blue!15}]
AAAAAAAA & 333 \\
BBBBB & 444 \\
AAAAAAAA & 333 \\
BBBBB & 444 \\
AAAAAAAA & 333 \\
BBBBB & 444 \\
AAAAAAAA & 333 \\
BBBBB & 444 \\
AAAAAAAA & 333 \\
BBBBB & 444 \\
AAAAAAAA & 333 \\
BBBBB & 444 \\
AAAAAAAA & 333 \\
BBBBB & 444 \\
\Block{2-1}{CCC} & 333 \\
                 & 444 \\
AAAAAAAA & 333 \\
BBBBB & 444 \\
\end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

0

You could surround your preceesing tables with \begingroup and \endgroup. The \rowcolor command will then be just active inside of this group. Other commands that change for example font size, font color, thickness of lines,... will also be affected and will only be active inside of this group.

I thus also included a second option, that locally resets the \rowcolor command for just this one table by using \rowcolors{1}{}{} instead of \rowcolors{1}{white}{white}.

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{float}
\begin{document}

\begingroup
\rowcolors{1}{white}{gray}
\begin{tabular}{ll}
text & text \\
text & text \\
text & text \\
text & text \\
text & text \\
\end{tabular}

**tables and other code**

\begin{tabular}{ll}
text & text \\
text & text \\
text & text \\
text & text \\
text & text \\
\end{tabular}
\endgroup

\begin{table}[H]
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{ | c | c | c | c | c | }
\hline
\multirow{2}{*}{teeeeeeeeest} & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1\\
\hline
& 1 & 1 & 1 & 1\\
\hline
\end{tabular}
\end{table}



\rowcolors{1}{white}{gray}
\begin{tabular}{ll}
text & text \\
text & text \\
text & text \\
text & text \\
text & text \\
\end{tabular}

**tables and other code**

\begin{tabular}{ll}
text & text \\
text & text \\
text & text \\
text & text \\
text & text \\
\end{tabular}


\begin{table}[H]
\rowcolors{1}{}{}
\renewcommand{\arraystretch}{1.5}
\centering
\begin{tabular}{ | c | c | c | c | c | }
\hline
\multirow{2}{*}{teeeeeeeeest} & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1\\
\hline
& 1 & 1 & 1 & 1\\
\hline
\end{tabular}
\end{table}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.