1

I wonder if there's a different way to do the alternate colors in a multirow tables. Everywhere people use "\multirow{-x}" but i would like to know if there's a way of doing it without any negative numbers and preferably not writing row by row. i'd like a table like this: i'd like a table like this

\rowcolors{1}{}{lightgray}
\centering
\caption{Multirow table with all cells in the same color.}\label{tab:multi row}
\begin{tabular}{p{5cm}p{5cm}}
\hline
Column 1 & Column 2\\
\hline
-&-\\
-&-\\
\cellcolor{lightgray}&Single-row\\
\cellcolor{lightgray}&Single-row\\
\multirow{-3}{*}{\cellcolor{lightgray}Multi-row (3)}&Single-row\\
-&-\\
-&-\\
\hline
\end{tabular}
\end{table}%

(not my code, got it here: https://texblog.org/2014/05/19/coloring-multi-row-tables-in-latex/)

1
  • 1
    You should have a look at the package nicematrix. Commented Sep 3, 2020 at 5:28

2 Answers 2

1

Assuming, a) the \multirow command spans an odd number of rows and b) the text in the multirow spans a single row, you can use something like the following:

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}

\begin{table}
\rowcolors{1}{}{lightgray}
\centering
\caption{Multirow table with all cells in the same color.}\label{tab:multi row}
\begin{tabular}{p{5cm}p{5cm}}
\hline
Column 1 & Column 2\\
\hline
- & - \\
- & - \\
 & Single-row \\
\cellcolor{lightgray}Multi-row (3) & Single-row \\
 & Single-row \\
- & - \\
- & - \\
\hline
\end{tabular}
\end{table}%

\end{document}
1

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\begin{document}

\begin{table}
\centering
\caption{Multirow table with all cells in the same color.}\label{tab:multi row}
\begin{NiceTabular}{p{5cm}p{5cm}}
\CodeBefore
  \rowcolors{1}{}{lightgray}
\Body
  \hline
  Column 1 & Column 2\\
  \hline
  - & - \\
  - & - \\
  \Block[l,fill=lightgray]{3-1}{Multi-row (3)} & Single-row \\
   & Single-row \\
   & Single-row \\
  - & - \\
  - & - \\
  \hline
\end{NiceTabular}
\end{table}

\end{document}

You need several compilations.

Output of the above code

You must log in to answer this question.

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