0

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!

1
  • Welcome to TeX SX! Which error do you have? Please add the relevant part of the .log file to you post.
    – Bernard
    Commented Jan 13, 2018 at 11:21

3 Answers 3

1

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}
1

you can colored rows with help of package xcolor with option ˙[table]` (see mwe below) using macro

    \rowcolors{2}{white}{gray!20}

before beginning of table. since \rowcolor overwrite \columncolor, the part of rowcolors in the first column had to be "over colored" by \cellcolor{white}. special care needed \multirow. that it is not covered by row colors had to be moved below a of spanned cells:

\multirow{-4}{*}{System (I)}
    & texto1    & texto2                    & texto3            & Texto 4           

for more space in rows i use package cellspace and add attribute S to appropriate column types. for better looking of table the vertical space around rules is removed.

special care is given to accommodate row colors to table width. since you use @{} on beginning and end of column definition with out it the color spill out of table. this is prevented by

>{\columncolor{white}[0pt][\tabcolsep]}l

in the first and inthe last column (see mwe below).

mwe:

\documentclass{report}
\usepackage[table]{xcolor}
\usepackage{booktabs, cellspace, multirow}
\renewcommand{\aboverulesep}{0pt}
\renewcommand{\belowrulesep}{0pt}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}


\begin{document}
\begin{table}
    \centering
    \rowcolors{2}{white}{gray!20}
\begin{tabular}{@{}>{\columncolor{white}[0pt][\tabcolsep]}l Sl l l
                   >{\columncolor{white}[\tabcolsep][0pt]}l@{}} % column definition is changed!
\toprule[0.5pt]
    & \multicolumn{2}{Sc}{\textbf{Method 1}}  & \multicolumn{2}{Sc}{\textbf{Method 2}}  \\
\cellcolor{white}
    & Iteration & Approximation           & Iteration         & Approximation       \\
    \cmidrule(r){2-3}\cmidrule(l){4-5}
    & texto1    & texto2                    & texto3            & Texto 4           \\
\cellcolor{white}
    & texto1    & texto2                    & texto3            & Texto 4           \\
    & texto1    & texto2                    & texto3            & Texto 4           \\
\cellcolor{white}
\multirow{-4}{*}{System (I)}
    & texto1    & texto2                    & texto3            & Texto 4           \\
\midrule
%
    & texto1    & texto2                    & texto3            & Texto 4           \\
\cellcolor{white}
    & texto1    & texto2                    & texto3            & Texto 4           \\
    & texto1    & texto2                    & texto3            & Texto 4           \\
\cellcolor{white}
\multirow{-4}{*}{System (I)}
    & texto1    & texto2                    & texto3            & Texto 4           \\
\bottomrule[0.5pt]
\end{tabular}
\caption{Comparison of the methods}
\end{table}
\end{document}

enter image description here

note: from your question is not very clear, if you like multirow cell white or also should be colored with gray strips. in latter case you need only to remove all \cellcolor{white} in table code.

edit: alternative scheme of a table coloring and use of horizontal rules which (to my opinion) better group rows and columns. table body in this case is:

enter image description here

\begin{table}
    \centering
    \rowcolors{2}{gray!20}{white}
\begin{tabular}{@{}>{\columncolor{white}[0pt][\tabcolsep]}l Sl l l
                   >{\columncolor{white}[\tabcolsep][0pt]}l@{}} % column definition is changed!
\toprule[0.5pt]
    & \multicolumn{2}{Sc}{\textbf{Method 1}}  & \multicolumn{2}{Sc}{\textbf{Method 2}}  \\
\cmidrule(r){2-3}\cmidrule(l){4-5}
    & Iteration & Approximation           & Iteration         & Approximation       \\
\midrule
\cellcolor{white}
    & texto1    & texto2                    & texto3            & Texto 4           \\
    & texto1    & texto2                    & texto3            & Texto 4           \\
 \cellcolor{white}
   & texto1    & texto2                    & texto3            & Texto 4           \\
\multirow{-4}{*}{System (I)}
    & texto1    & texto2                    & texto3            & Texto 4           \\
\midrule
%
\cellcolor{white}
    & texto1    & texto2                    & texto3            & Texto 4           \\
    & texto1    & texto2                    & texto3            & Texto 4           \\
\cellcolor{white}
    & texto1    & texto2                    & texto3            & Texto 4           \\
\multirow{-4}{*}{System (I)}
    & texto1    & texto2                    & texto3            & Texto 4           \\
\bottomrule[0.5pt]
\end{tabular}
\caption{Comparison of the methods}
\end{table}
0

With {NiceTabular} of nicematrix (and its key color-inside), you only have to add an instruction \rowcolors{}{gray!20} in the second column of the fourth row. The coloring of the rows will start at the fourth row (because the instruction is in the row 4) and will apply to the column on the right the second column (because the instruction is in the column 2).

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

\begin{document}

\begin{table}
\centering

\begin{NiceTabular}{@{}lllll@{}}[color-inside]
\toprule[0.5pt]
  & \multicolumn{2}{c}{Method 1} & \multicolumn{2}{c}{Method 2}\\
   & Iteration & Approximation & Iteration & Approximation \\
  \cmidrule(lr){2-3}\cmidrule(l){4-5}
  \multirow{4}{*}{System (I)}  &  
  \rowcolors{}{gray!20} 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{NiceTabular}
\caption{Comparison of the methods}
\end{table}

\end{document}

Output of the above code

You must log in to answer this question.

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