
看來如果我使用>{\columncolor{green!30}}c
和該列中有\multirow
內容,顏色最終出現在前景中。
這兩個表的唯一差異是第二個表已>{\columncolor{green!30}}
應用於第一列,而第一個表則沒有。
代碼:
\documentclass{article}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{multirow}
\newcommand*{\MyTabelContent}{%
\toprule
&$+$ & 0 & 1 & 2 & 3 & 4 & 5
\\
\multirow{6}{*}{\rotatebox{90}{Label}}
&0 & & & & & &
\\
&1 & & & & & &
\\
&2 & & & & & &
\\
&3 & & & & & &
\\
&4 & & & & & &
\\
&5 & & & & & &
\\
\bottomrule
}
\begin{document}
\noindent
\begin{tabular}{c >{\columncolor{cyan!30}}cccccc c @{}}
\MyTabelContent
\end{tabular}
\quad
\begin{tabular}{>{\columncolor{green!30}}c >{\columncolor{cyan!30}}cccccc c @{}}
\MyTabelContent
\end{tabular}%
\end{document}
答案1
\multirow
您可以透過在最底部行中使用並指定負行數來獲得所需的內容。
\documentclass{article}
\usepackage[table]{xcolor} % also loads colortbl
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand*{\MyTabelContent}{%
\toprule
&$+$ & 0 & 1 & 2 & 3 & 4 & 5
\\
&0 & & & & & &
\\
&1 & & & & & &
\\
&2 & & & & & &
\\
&3 & & & & & &
\\
&4 & & & & & &
\\
\multirow{-6}{*}{\rotatebox{90}{Label}}
&5 & & & & & &
\\
\bottomrule
}
\begin{document}
\noindent
\begin{tabular}{c >{\columncolor{cyan!30}}cccccc c @{}}
\MyTabelContent
\end{tabular}
\quad
\begin{tabular}{>{\columncolor{green!30}}c >{\columncolor{cyan!30}}cccccc c @{}}
\MyTabelContent
\end{tabular}%
\end{document}
答案2
使用{NiceTabular}
of nicematrix
(和 key colortbl-like
),您可以直接得到預期的結果。
\documentclass{article}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{nicematrix}
\newcommand*{\MyTabelContent}{%
\toprule
&$+$ & 0 & 1 & 2 & 3 & 4 & 5
\\
\multirow{6}{*}{\rotatebox{90}{Label}}
&0 & & & & & &
\\
&1 & & & & & &
\\
&2 & & & & & &
\\
&3 & & & & & &
\\
&4 & & & & & &
\\
&5 & & & & & &
\\
\bottomrule
}
\begin{document}
\noindent
\begin{NiceTabular}{c >{\columncolor{cyan!30}}ccccccc@{}}[colortbl-like]
\MyTabelContent
\end{NiceTabular}
\quad
\begin{NiceTabular}{>{\columncolor{green!30}}c >{\columncolor{cyan!30}}ccccccc@{}}[colortbl-like]
\MyTabelContent
\end{NiceTabular}%
\end{document}
彩色面板延伸至 的booktabs
設計規則nicematrix
。
您需要多次編譯(因為nicematrix
在背景使用 PGF/Tikz 節點)。