20

The \multirow text is covered by the background color. Does someone know why and can fix it?

enter image description here

\begin{table}[h]
    \caption{caption} 
    \label{tab} 
    \centering
    \begin{tabular}{cccccc}
        \toprule
        & & A & B & C & D \\
        \midrule
        \rowcolor{gray!10}
            \multirow{2}{*}{Rosso}  & Pruning & - & - & 6-C-Pr & - \\
        \rowcolor{gray!10}
                                & Stalks & - & - & 6-C-S & - \\
            \multirow{2}{*}{Verde}  & Pruning & - & - & 6-M-Pr & - \\
                                & Stalks & - & - & 6-M-S & - \\
        \rowcolor{gray!10}
            \multirow{2}{*}{Blu}    & Pruning & 4-Pa-Pr & 5-Pa-Pr & 6-Pa-Pr & 7-Pa-Pr \\
        \rowcolor{gray!10}
                                & Stalks & 4-Pa-S & 5-Pa-S & 6-Pa-S & 7-Pa-S \\
            \multirow{2}{*}{Bianco}         & Pruning & - & - & 6-W-Pr & - \\
                                & Stalks & - & - & 6-W-Pr & - \\
            \bottomrule
        \end{tabular}
\end {table}
2
  • Please add a MWE, would be helpful.... Sep 25, 2015 at 20:29
  • I'm sure this is a duplicate, but anyway you need to put the text on top of the colour not behind it so put the entry on the last row and use a negative number of rows so it spans up. (unrelated but don't use [h] it normally just generates a warning that latex is changing it to ht) Sep 26, 2015 at 0:16

3 Answers 3

28

If the \multirow command is placed on the upper of the two rows, then its text is placed and the next table line with \rowcolor will overprint the lower part. Therefore, \multirow is better moved to the lower of the two rows. Then the background color of the two rows is already set, when the text of \multirow is placed:

\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{multirow}

\begin{document}
\begin{table}[h]
  \caption{caption}
  \label{tab}
  \centering
  \begin{tabular}{cccccc}
    \toprule
    & & A & B & C & D \\
    \midrule
    \rowcolor{gray!10}
    & Pruning & -- & -- & 6-C-Pr & -- \\
    \rowcolor{gray!10}
    \multirow{-2}{*}{Rosso}
    & Stalks & -- & -- & 6-C-S & -- \\
    & Pruning & -- & -- & 6-M-Pr & -- \\
    \multirow{-2}{*}{Verde}
    & Stalks & -- & -- & 6-M-S & -- \\
    \rowcolor{gray!10}
    & Pruning & 4-Pa-Pr & 5-Pa-Pr & 6-Pa-Pr & 7-Pa-Pr \\
    \rowcolor{gray!10}
    \multirow{-2}{*}{Blu}
    & Stalks & 4-Pa-S & 5-Pa-S & 6-Pa-S & 7-Pa-S \\
    & Pruning & -- & -- & 6-W-Pr & -- \\
    \multirow{-2}{*}{Bianco}
    & Stalks & -- & -- & 6-W-Pr & -- \\
    \bottomrule
  \end{tabular}
\end {table}
\end{document}

Result

4

I propose the following improvement to the table: as booktabs introduces vertical spacing around rules, which results in white strips in coloured rows, I replace the rule commands from booktabs with variable width rule commands from the small boldline package, from the shipunov bundle, and add vertical padding above and below row cells with cellspace package, which ensures a minimal vertical spacing at the top and the bottom of every cell of columns prefixed by the letter S.

\documentclass{article}

\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{boldline}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\begin{document}

\begin{table}[h]
  \caption{caption}
  \label{tab}
  \centering
  \begin{tabular}{*{6}{Sc}}
    \hlineB{2}
    & & A & B & C & D \\
   \hlineB{1.25}
    \rowcolor{gray!10}
    & Pruning & -- & -- & 6-C-Pr & -- \\
    \rowcolor{gray!10}
    \multirow{-2}{*}{Rosso}
    & Stalks & -- & -- & 6-C-S & -- \\
    & Pruning & -- & -- & 6-M-Pr & -- \\
    \multirow{-2}{*}{Verde}
    & Stalks & -- & -- & 6-M-S & -- \\
    \rowcolor{gray!10}
    & Pruning & 4-Pa-Pr & 5-Pa-Pr & 6-Pa-Pr & 7-Pa-Pr \\
    \rowcolor{gray!10}
    \multirow{-2}{*}{Blu}
    & Stalks & 4-Pa-S & 5-Pa-S & 6-Pa-S & 7-Pa-S \\
    & Pruning & -- & -- & 6-W-Pr & -- \\
    \multirow{-2}{*}{Bianco}
    & Stalks & -- & -- & 6-W-Pr & -- \\
    \hlineB{2}
  \end{tabular}
\end {table}

\end{document} 

enter image description here

2
  • the boldline package is very attractive, but I can not find anything what remain on manual about this package :-(. The one page documentation is not very informative. Seems that this package define only \hlineB{<thickness>}. Can you point me, if somewhere is more information about it?
    – Zarko
    Sep 25, 2015 at 21:36
  • @Zarko: The only documentation is an example file. It defines \hlineB, \clineB and V for vertical rules (the latter replaces |, but is a column type really). The argument is a number (num times \linewidth). The same functionality for horizontal rules only is possible with the \Xhline and \Xcline commands from makecell, with a length argument.
    – Bernard
    Sep 25, 2015 at 23:04
2

You can construct that table with {NiceTabular} of nicematrix with the following avantages:

  • The colored rows will automatically respect the rules of booktabs.
  • You don't have to put \multicolumn with a negative argument: you use \Block with a positive argument.
  • You can color alternatively the logical rows with a command \rowcolors in the \CodeBefore.
  • You will have a good output in all the PDF viewers at all levels of zoom (better than with colortbl).

There is a drawback: you need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

\documentclass{article}
\usepackage{caption}
\usepackage{nicematrix}
\usepackage{booktabs}

\begin{document}


\begin{table}[h]
\caption{caption}
\label{tab}
\centering
\begin{NiceTabular}{*{6}{c}}[cell-space-limits=4pt]
\CodeBefore
  \rowcolors{1}{}{gray!10}[respect-blocks]
\Body
  \toprule
  & & A & B & C & D \\
 \midrule
  \Block{2-1}{Rosso}
  & Pruning & -- & -- & 6-C-Pr & -- \\
  & Stalks & -- & -- & 6-C-S & -- \\
  \Block{2-1}{Verde}
  & Pruning & -- & -- & 6-M-Pr & -- \\
  & Stalks & -- & -- & 6-M-S & -- \\
  \Block{2-1}{Blu}
  & Pruning & 4-Pa-Pr & 5-Pa-Pr & 6-Pa-Pr & 7-Pa-Pr \\
  & Stalks & 4-Pa-S & 5-Pa-S & 6-Pa-S & 7-Pa-S \\
  \Block{2-1}{Bianco}
  & Pruning & -- & -- & 6-W-Pr & -- \\
  & Stalks & -- & -- & 6-W-Pr & -- \\
  \bottomrule
\end{NiceTabular}
\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 .