0

I am having issues working with multirow in my table, I cannot figure out how to center a vertical row and how to color all the cells related to it.

I am trying to create this table:

Table and its problems

This is the code that I am using to create the table above:

\usepackage{adjustbox}
\usepackage{multirow}
\usepackage[table, x11names]{xcolor}
\usepackage{array}

\newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}

\begin{table}
\caption{Just a nice table}
\begin{center}
\renewcommand{\arraystretch}{5.5}
\begin{tabular}{|c|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|}
\hline
\multicolumn{2}{|M{2.0cm}|}{name A} & name B & name C & name D & name E & name F\\
\hline
\multirow{2}{*}{\parbox[t]{2mm}{\rotatebox[origin=c]{90}{Classification A1}}} & B & C & D & E & F & G\\
\cline{2-7}
& B & C & D & E & F & G\\
\cline{2-7}
& B & C & D & E & F & G\\
\hline
\multirow{2}{*}{\parbox[t]{2mm}{\rotatebox[origin=c]{90}{Classification A2}}}\cellcolor{blue!25} & B & C & D & E & F & G\\
\cline{2-7}
& B & C & D & E & F & G\\
\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

Probably I am messing it up using \arraystretch regarding the centering problem, but I need to use it because the "Classification" name would go out of the table. Is there a different way to handle it?

The color problem I don't know if there is a function to deal with multiple rows without painting over the written part.

Another problem when I use the multirow is that a white or "ghost" row appears between the colored rows. As you can see below:

enter image description here

Any help would be very welcome.

2 Answers 2

1
  1. The first \multirow should cover 3 rows instead of 2.
  2. You must color both cells that the second \multirow covers. But then you should put the \multirowin the last row with a negative count to prevent the color overwriting the text (see themultirow` documentation).
  3. You might also have a look at the tabular package which is more powerful for complicated tables (although I wouldn't classify this one as complicated).
\documentclass{article}
\usepackage{adjustbox}
\usepackage{multirow}
\usepackage[table, x11names]{xcolor}
\usepackage{array}

\newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}
\begin{document}

\begin{table}
\caption{Just a nice table}
\begin{center}
\renewcommand{\arraystretch}{5.5}
\begin{tabular}{|c|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|}
\hline
\multicolumn{2}{|M{2.0cm}|}{name A} & name B & name C & name D & name E & name F\\
\hline
\multirow{3}{*}{\parbox[t]{2mm}{\rotatebox[origin=c]{90}{Classification A1}}} & B & C & D & E & F & G\\
\cline{2-7}
& B & C & D & E & F & G\\
\cline{2-7}
& B & C & D & E & F & G\\
\hline
\cellcolor{blue!25} & B & C & D & E & F & G\\
\cline{2-7}
\multirow{-2}{*}{\parbox[t]{2mm}{\rotatebox[origin=c]{90}{Classification A2}}}\cellcolor{blue!25}& B & C & D & E & F & G\\
\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document}

enter image description here

0
2

The first argument of \multirow is for standard (one-lined) rows, so you have to determine, by trial & error the number of equivalent standard rows. Note this number is not necessarily an integer.

For the coloured \multirow, you have to use \cellcolor{…} also in the empty cells covered by the multirow.

Ol also simplified a bit your code; using \parbox is not necessary for the rotated boxes.

\documentclass{article}
\usepackage{geometry}
\usepackage{adjustbox}
\usepackage{multirow}
\usepackage[table, x11names]{xcolor}
\usepackage{array}

\newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}

\begin{document}

\begin{table}
\caption{Just a nice table}
\begin{center}
\renewcommand{\arraystretch}{5.5}
\begin{tabular}{|c|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|M{2.0cm}|}
\hline
\multicolumn{2}{|M{2.0cm}|}{name A} & name B & name C & name D & name E & name F\\
\hline
\multirow{3.1}{*}{\rotatebox[origin=c]{90}{Classification A1}} & B & C & D & E & F & G\\
\cline{2-7}
& B & C & D & E & F & G\\
\cline{2-7}
& B & C & D & E & F & G\\
\hline
\cellcolor{blue!25}& B & C & D & E & F & G\\
\cline{2-7}
\multirow{-2}{*}{\cellcolor{blue!25} \rotatebox[origin=c]{90}{Classification A2}}& B & C & D & E & F & G\\
\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}

\end{document} 

enter image description here

10
  • Thank you, it worked! Just one question regarding the color. When I zoom in on the blue area of the table, there is a white (ghost) row dividing the multirow (between the 2 Bs). This white row crosses the 'a' of "Classification A2". I've added a print in the question, to better understand the problem. Do you know how to solve this?
    – Codewraith
    Dec 1, 2021 at 16:10
  • Are you using Acrobat Reader to view the PDF? I have heard that this is an artefact of how PDF viewers do the rounding of pixels and that Acrobat Reader is the only one that does it correctly. Dec 1, 2021 at 16:18
  • I am using Overleaf to write my article. I am not sure which PDF reader it uses. The only way to "solve" this problem, is using the nicematrix package, but if there is a way to solve this without an extra package I guess it would be better...
    – Codewraith
    Dec 1, 2021 at 16:28
  • 1
    @Codewraith: I've checked. Indeed there remains a very thin padding of the \hhline , which remains uncoloured. Your white lines are to the ], which results from a mistyping. Anyway, there is a simple solution without hhline: replace \cline{2-7} with \noalign{\vskip 0.2pt} \cline{2-7}. On my pdfviewer, there's no white thin line in the first column.
    – Bernard
    Dec 2, 2021 at 10:31
  • 1
    @Codewraith: I'm sorry, I mistyped, forgetting the , and forgot to check what I wrote. Actually, in my LaTeX editor, I used $vskip –0.2pt.
    – Bernard
    Dec 3, 2021 at 9:31

You must log in to answer this question.

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