如果使用 \multirow,前景中的 \columncolor

如果使用 \multirow,前景中的 \columncolor

看來如果我使用>{\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 節點)。

上述程式碼的輸出

相關內容