
Eu tenho a seguinte tabela
\newcommand{\headrow}{\rowcolor{black!20}}
\definecolor{Gray}{gray}{0.90}
\begin{table}[ht]\rowcolors{1}{Gray}{white}
\begin{center}
\caption{Test Table}
\begin{tabular}{l|cccccccc}
\hline
\headrow
\multirow{2}{1.7cm}{\textbf{Approach}}& \multicolumn{8}{c}{\centering \textbf{Test}}\\
\cline{2-9}
& \multicolumn{1}{c}{\textbf{A}} & \multicolumn{1}{c}{\textbf{B}}& \multicolumn{1}{c}{\textbf{C}} & \multicolumn{1}{c}{\textbf{D}}& \multicolumn{1}{c}{\textbf{E}} & \multicolumn{1}{c}{\textbf{F}}
& \multicolumn{1}{c}{\textbf{G}}& \multicolumn{1}{c}{\textbf{H}}\\
\hline
App1 & && && &&&
\\
App2 && &&& &&&
\\
\hline
\end{tabular}
\end{center}
\end{table}
A saída é a seguinte
Como você notou, a linha do cabeçalho tem duas cores cinza, uma forma \headrow e outra da minha definição de cor cinza.
Então, como posso ter para o cabeçalho a mesma cor de \headrow e tornar a palavra Approch visível?
Responder1
Com {NiceTabular}
of nicematrix
, você terá um resultado quase perfeito no visualizador de PDF (por exemplo, você não verá as linhas brancas finas que vê nos visualizadores que usam MuPDF como o SumatraPDF).
No entanto, você precisa de várias compilações.
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\definecolor{Gray}{gray}{0.90}
\begin{table}[ht]
\caption{Test Table}
\begin{NiceTabular}{l|cccccccc}%
[code-before = \rowcolors{3}{}{Gray} \rowcolor{black!20}{1,2}]
\hline
\Block{2-1}{\textbf{Approach}} & \multicolumn{8}{c}{\textbf{Test}}\\
\cline{2-9}
& \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F}
& \textbf{G} & \textbf{H} \\
\hline
App1 \\
App2 \\
\hline
\end{NiceTabular}
\end{table}
\end{document}
Responder2
Uma solução simples consiste em adicionar \multirow{-2}
no início da linha seguinte e adicionar \cellcolor{black!20}
dentro do \multiro. Não relacionado: adicionei o caption
pacote para ter um espaçamento entre a legenda e a tabela. Também removi todo o desnecessário \multicolumn{1}{c}{…}
na linha de títulos. Última observação: não use center
dentro de uma tabela: ele adiciona espaçamento vertical indesejado ao espaçamento normal do ambiente da tabela. ambiente.
\documentclass{article}
\usepackage{multirow, caption}
\usepackage[table]{xcolor}
\newcommand{\headrow}{\rowcolor{black!20}}
\begin{document}
\definecolor{Gray}{gray}{0.90}
\begin{table}[ht]\rowcolors{3}{}{Gray}
\setlength{\extrarowheight}{2pt}
\centering
\caption{Test Table}
\begin{tabular}{l|*{8}{c}}
\hline
\headrow & \multicolumn{8}{c}{\centering \textbf{Test}}\\
\cline{2-9}
\headrow \multirow{-2}{1.7cm}{\textbf{Approach}} & \textbf{A} & \textbf{B}& \textbf{C} & \textbf{D}& \textbf{E} & \textbf{F}
& \textbf{G}& \textbf{H}\\
\hline
App1 & && && &&&
\\
App2 && &&& &&&
\\
\hline
\end{tabular}
\end{table}
\end{document}