
tengo la siguiente tabla
\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}
La salida es la siguiente
Como habrás notado, la fila del encabezado tiene dos colores grises, uno de \headrow y otro de mi definición del color gris.
Entonces, ¿cómo puedo tener el mismo color para el encabezado que el de \headrow y hacer visible la palabra Approch?
Tenga en cuenta que, cuando uso nicematrix, aparece el siguiente error
Respuesta1
Con {NiceTabular}
of nicematrix
, tendrás un resultado casi perfecto en el visor de PDF (por ejemplo, no verás las finas líneas blancas que ves en los visores que usan MuPDF como SumatraPDF).
Sin embargo, necesitas varias compilaciones.
\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}
Respuesta2
Una solución sencilla consiste en añadir \multirow{-2}
al principio de la siguiente línea y añadir \cellcolor{black!20}
dentro del \multiro. No relacionado: agregué el caption
paquete para tener un espacio decantado entre el título y la tabla. También eliminé todo lo innecesario \multicolumn{1}{c}{…}
en la fila de títulos. Última observación: no utilice center
dentro de una tabla: agrega un espaciado vertical no deseado al espaciado normal del entorno de la tabla. 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}