[Tex/LaTex] Alternate color in multirows

colortables

I have the follwoing table:

\begin{table}
\centering
\begin{tabular}{@{}l*2{>{}l}%
  l<{}l@{}}
\toprule[0.5pt]
  & \multicolumn{2}{c}{\head{Method 1}} & \multicolumn{2}{c}{\head{Method 2}}\\
   & Iteration & Approximation & Iteration & Approximation \\
  \cmidrule(lr){2-3}\cmidrule(l){4-5}
  \multirow{4}{*}{System (I)}  &  texto1 & texto2 & texto3 & Texto 4\\
  & texto1 & texto2 & texto3 & Texto 4 \\
  &  texto1 & texto2 & texto3 & Texto 4 \\
  &  texto1 & texto2 & texto3 & Texto 4 \\
%  
  \cmidrule(lr){2-3}\cmidrule(l){4-5}
  \multirow{4}{*}{System (II)} &  texto1 & texto2 & texto3 & Texto 4\\
  & texto1 & texto2 & texto3 & Texto 4 \\
  &  texto1 & texto2 & texto3 & Texto 4 \\
  &  texto1 & texto2 & texto3 & Texto 4 \\
\bottomrule[0.5pt]
\end{tabular}
\caption{Comparison of the methods}
\end{table}

and I am using the package \usepackage{xcolor} because \usepackage[table]{xcolor} return an error…

I would like to coloed some rows of the Table, specifically, in this way:

texto1 & texto2 & texto3 & Texto 4\ —>White

& texto1 & texto2 & texto3 & Texto 4 \ —>Gray

& texto1 & texto2 & texto3 & Texto 4 \ —>White

& texto1 & texto2 & texto3 & Texto 4 \ —>Gray

Some idea??

Many thanks in advance for your comments!

Best Answer

I do not know which error you are getting, you can try loading \usepackage{xcolor} and \usepackage{colortbl} separately.

To obtain the desired effect, you need to place your \multirow entries on the last row they span, instead of the first one, and use a negative number of rows:

\multirow{-4}{*}{System (I)}

This ensures that the coloring of the rows does not cover the \multirow, see this.

Then, at the beginning of each one of the rows you want colored, you add

\rowcolor{gray!50} \cellcolor{white}

which will make that row gray, but keep the first cell white. Full code at the bottom of the post.

colortbl

\documentclass{report}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}

\begin{document}



\begin{table}
    \centering
    \begin{tabular}{@{}l*2{l}%
            ll@{}}
        \toprule[0.5pt]
        & \multicolumn{2}{c}{\head{Method 1}} & \multicolumn{2}{c}{\head{Method 2}}\tabularnewline
        & Iteration & Approximation & Iteration & Approximation \tabularnewline
        \cmidrule(lr){2-3}\cmidrule(l){4-5} 
        &   texto1 & texto2 & texto3 & Texto 4\tabularnewline
        \rowcolor{gray!50} \cellcolor{white} & texto1 & texto2 & texto3 & Texto 4 \tabularnewline
        &  texto1 & texto2 & texto3 & Texto 4 \tabularnewline
        \rowcolor{gray!50} \cellcolor{white} \multirow{-4}{*}{System (I)} &  texto1 & texto2 & texto3 & Texto 4 \tabularnewline
        %  
        \cmidrule(lr){2-3}\cmidrule(l){4-5}
        &  texto1 & texto2 & texto3 & Texto 4\tabularnewline
        \rowcolor{gray!50} \cellcolor{white} & texto1 & texto2 & texto3 & Texto 4 \tabularnewline
        &  texto1 & texto2 & texto3 & Texto 4 \tabularnewline
        \rowcolor{gray!50} \cellcolor{white} \multirow{-4}{*}{System (II)} &  texto1 & texto2 & texto3 & Texto 4 \tabularnewline
        \bottomrule[0.5pt]
    \end{tabular}
    \caption{Comparison of the methods}
\end{table}

\end{document}
Related Question