\columncolor im Vordergrund, wenn \multirow verwendet wird

\columncolor im Vordergrund, wenn \multirow verwendet wird

Es scheint, dass wenn ich>{\columncolor{green!30}}c UndWenn sich in dieser Spalte Inhalt befindet \multirow, landet die Farbe im Vordergrund.

Der einzige Unterschied zwischen diesen beiden Tabellen besteht darin, dass die zweite >{\columncolor{green!30}}auf die erste Spalte angewendet wird und die erste Tabelle nicht.

Bildbeschreibung hier eingeben

Code:

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

Antwort1

Sie erhalten das gewünschte Ergebnis, indem Sie es \multirowin der untersten Zeile verwenden und eine negative Zeilenanzahl angeben.

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

Bildbeschreibung hier eingeben

Antwort2

Mit {NiceTabular}of nicematrix(und der Taste colortbl-like) erhalten Sie direkt das erwartete Ergebnis.

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

Die farbigen Tafeln erstrecken sich bis zu den Regeln der booktabsGestaltung von nicematrix.

Sie benötigen mehrere Kompilierungen (da nicematrixim Hintergrund PGF/Tikz-Knoten verwendet werden).

Ausgabe des obigen Codes

verwandte Informationen