TeX - LaTeX Asked by user2869180 on February 22, 2021
I have the following table
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}
Th output is the following
So as you notice, the header row has two gray colors , one form headrow and one from my definition of the gray color.
So, how I can have for the header the same color as one from headrow and make the word Approch visible?
Note that, when using the nicematrix, I get the following error
With {NiceTabular}
of nicematrix
, you will have a result almost perfect in the PDF viewer (for instance, you won't see the thin white lines you see in the viewers using MuPDF such as SumatraPDF).
However, you need several compilations.
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}
Correct answer by F. Pantigny on February 22, 2021
A simple solution consists in adding multirow{-2}
at the beginning of the follwing line and adding cellcolor{black!20}
inside the multiro. Unrelated: I added the caption
package to have a decant spacing between caption and table. I also removed all the unnecessary multicolumn{1}{c}{…}
in the headings row. Last remark: don't use the center
within a table: it adds unwanted vertical spacing to the normal spacing of the table environment. environment.
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}
Answered by Bernard on February 22, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP