複数色の複数行テーブル(\multirow{-x​​} は使用しない)

複数色の複数行テーブル(\multirow{-x​​} は使用しない)

複数行の表で交互に色を付ける別の方法があるかどうか疑問に思います。どこでも「\multirow{-x​​}」が使われていますが、負の数を使わず、できれば行ごとに書かずにそれを実行する方法があるかどうか知りたいです。次のような表が欲しいです:このようなテーブルが欲しいです

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

(私のコードではありません。ここから入手しました:https://texblog.org/2014/05/19/coloring-multi-row-tables-in-latex/

答え1

a)\multirowコマンドが奇数行にまたがり、b) 複数行内のテキストが 1 行にまたがると仮定すると、次のようなものを使用できます。

ここに画像の説明を入力してください

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

答え2

最新バージョンnicematrix(2020-09-03 の v. 5.3)でこれを行うことができます。

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

複数のコンパイルが必要です。

上記コードの出力

関連情報