1

I'm trying to merge some cells in a colored table. For now, the table looks like :

enter image description here

I am trying to merge the four cells marked yy, and choose a custom color for them (the color thing is optional but would be nice).

I have tried doing so with the rows 2 to 5, but unfortunately, no merging, and the text destined to the cell doesn't appear.

My code for the table is :

\begin{table}[H]
    \sffamily
    \arrayrulecolor{white}
    \arrayrulewidth=1pt
    \renewcommand{\arraystretch}{1.5}
    \rowcolors[\hline]{1}{.!50!White}{}
    \centering
    \begin{tabular}{@{} A|B|C @{}} 
        \cellcolor{ForestGreen}\arraycolor{White}\bfseries & 
        \cellcolor{ForestGreen}\arraycolor{White}\bfseries B & 
        \cellcolor{ForestGreen}\arraycolor{White}\bfseries C \\ 
        \arraycolor{Black}
        \multirow{4}{*}{xx} & \multicolumn{1}{l}{a2} & \multicolumn{1}{l}{b2} \\\cline{2-3}
                            & \multicolumn{1}{l}{a3} & \multicolumn{1}{l}{b3} \\\cline{2-3}
                            & \multicolumn{1}{l}{a4} & \multicolumn{1}{l}{b4} \\\cline{2-3}
                            & \multicolumn{1}{l}{a5} & \multicolumn{1}{l}{b5} \\\hline
        \rotatebox{90}{yy}  &   a6& b6\\
        \rotatebox{90}{yy}  &   a7& b7\\
        \rotatebox{90}{yy}  &   a8& b8\\
        \rotatebox{90}{yy}  &   a9& b9\\
    \end{tabular}
    \caption{caption}
    \label{tab::buffer_order}
\end{table}

And my preamble contains the following :

\usepackage[
dvipsnames, % defines the use of the colors from the dvips / SVG set
table, % allows the use of colors in tables
]{xcolor}

\usepackage{floatrow}

\usepackage{multirow}

\usepackage{graphicx}

% defines column types for colored tables
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{LimeGreen!50!white}}m{1cm}}
\newcolumntype{B}{>{\columncolor{LimeGreen!50!white}}m{5cm}}
\newcolumntype{C}{>{\columncolor{LimeGreen!50!white}}m{6cm}}

Basically, I am trying to vertically merge cells in the first column, as to only have three cells in that column, in which the text is written vertically; while keeping the color scheme for the rest of the line, and possibly choosing the color of the merged cells.

2 Answers 2

1

With multirow placed in the last of the corresponding 4 rows (use -4 instead of 4 then) the text shows up. In order to get a unifomly colored cell without white lines cutting through, I have used hhline:

enter image description here

\documentclass{article}
\usepackage[
dvipsnames, % defines the use of the colors from the dvips / SVG set
table, % allows the use of colors in tables
]{xcolor}

\usepackage{floatrow}

\usepackage{multirow}

\usepackage{graphicx}

% defines column types for colored tables
\newcommand*{\arraycolor}[1]{\protect\leavevmode\color{#1}}
\newcolumntype{A}{>{\columncolor{LimeGreen!50!white}}m{1cm}}
\newcolumntype{B}{>{\columncolor{LimeGreen!50!white}}m{5cm}}
\newcolumntype{C}{>{\columncolor{LimeGreen!50!white}}m{6cm}}

\usepackage{hhline}

\begin{document}

\begin{table}[H]
    \sffamily
    \arrayrulecolor{white}
    \arrayrulewidth=1pt
    \renewcommand{\arraystretch}{1.5}
    \centering
    \begin{tabular}{ A|B|C @{}} 
        \cellcolor{ForestGreen}\arraycolor{White}\bfseries & 
        \cellcolor{ForestGreen}\arraycolor{White}\bfseries B & 
        \cellcolor{ForestGreen}\arraycolor{White}\bfseries C \\ 
        \hhline{---}
         & \multicolumn{1}{l}{a2} & \multicolumn{1}{l}{b2} \\
        \hhline{>{\arrayrulecolor{LimeGreen!50!white}}->{\arrayrulecolor{white}}|-|-}
                            & \multicolumn{1}{l}{a3} & \multicolumn{1}{l}{b3} \\
        \hhline{>{\arrayrulecolor{LimeGreen!50!white}}->{\arrayrulecolor{white}}|-|-}
                            & \multicolumn{1}{l}{a4} & \multicolumn{1}{l}{b4} \\ 
        \hhline{>{\arrayrulecolor{LimeGreen!50!white}}->{\arrayrulecolor{white}}|-|-}
        \multirow{-4}{*}{xx} & \multicolumn{1}{l}{a5} & \multicolumn{1}{l}{b5} \\ \hline
        \rowcolor{LimeGreen!25!white}\cellcolor{yellow}  &   a6& b6\\
        \hhline{>{\arrayrulecolor{yellow}}->{\arrayrulecolor{white}}|--}
        \cellcolor{yellow}  &   a7& b7\\
        \hhline{>{\arrayrulecolor{yellow}}->{\arrayrulecolor{white}}|--}
        \rowcolor{LimeGreen!25!White}\cellcolor{yellow}  &   a8& b8\\
        \hhline{>{\arrayrulecolor{yellow}}->{\arrayrulecolor{white}}|--}
        \cellcolor{yellow}\multirow{-4}{*}{\cellcolor{yellow}\rotatebox[origin=c]{90}{yy}}  &   a9& b9\\
    \end{tabular}
    \caption{caption}
    \label{tab::buffer_order}
\end{table}

\end{document}
3
  • You replaced \rowcolors[\hline]{1}{.!50!White}{} by \arrayrulecolor{white}. Does it have the same effect, except that yours is "more clean" ? Also, thank you for your answer. May 12, 2020 at 17:26
  • Wait I just noticed. With your answer, I don't have the color pattern that I want with the green : dark green / light green / dark green / light green for all the cells that are not merged or part of the header line :( May 12, 2020 at 17:30
  • Sorry, I didn't notice the alternating color was missing. I added it back in with two manual \rowcolor commands.
    – leandriis
    May 12, 2020 at 18:27
1

You can do that with nicematrix and you don't need hhline nor multirow nor colortbl.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{floatrow}
\usepackage{nicematrix}

\begin{document}

\begin{table}[H]
\sffamily
\renewcommand{\arraystretch}{1.5}
\centering
\begin{NiceTabular}{m{1cm}|m{5cm}|m{6cm}}[rules={color=white,width=1pt}]
  \CodeBefore
    \rowcolors{6}{LimeGreen!50!white}{LimeGreen!25!white}[cols=2-3]
    \rowcolor{ForestGreen}{1}
  \Body
  \RowStyle[color=white]{\bfseries}
    & B & C \\ 
    \hline
    \Block[fill=LimeGreen!50!white]{4-1}{xx} 
                    & a2 & b2 \\
                    & a3 & b3 \\
                    & a4 & b4 \\ 
                    & a5 & b5 \\ \hline
    \Block[fill=yellow]{4-1}{\rotate yy} 
                    & a6 & b6 \\
                    & a7 & b7 \\
                    & a8 & b8 \\
                    & a9& b9  \\ 
\end{NiceTabular}
\caption{caption}
\label{tab::buffer_order}
\end{table}

\end{document}

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

Result of the above code

You must log in to answer this question.

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