tablas de varias filas multicolores (sin usar \multirow{-x})

tablas de varias filas multicolores (sin usar \multirow{-x})

Me pregunto si hay una manera diferente de hacer los colores alternos en tablas de varias filas. En todas partes la gente usa "\multirow{-x}", pero me gustaría saber si hay alguna manera de hacerlo sin números negativos y preferiblemente sin escribir fila por fila. Me gustaría una mesa como esta:Me gustaría una mesa como esta

\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}%

(no es mi código, lo tengo aquí:https://texblog.org/2014/05/19/coloring-multi-row-tables-in-latex/)

Respuesta1

Suponiendo que a) el \multirowcomando abarca un número impar de filas yb) el texto en varias filas abarca una sola fila, puede usar algo como lo siguiente:

ingrese la descripción de la imagen aquí

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

Respuesta2

Puedes hacerlo con la última versión de nicematrix(v. 5.3 del 2020-09-03).

\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}}[code-before = \rowcolors{1}{}{lightgray}]
\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}

Necesitas varias compilaciones.

Salida del código anterior

información relacionada