여러 색상의 다중 행 테이블(\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) 여러 행의 텍스트가 단일 행에 걸쳐 있다고 가정하면 다음과 같이 사용할 수 있습니다.

여기에 이미지 설명을 입력하세요

\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최신 버전 (v. 5.3 of 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}

여러 가지 편집이 필요합니다.

위 코드의 출력

관련 정보