TeX - LaTeX Asked on July 30, 2021
Note: I know there were other people asking the same question here and here, but none of there examples were minimal, and I’m still confuzzled. Sorry for the inconvience.
I know I can do this:
%rowcolor-multirow-test.tex
documentclass{report}
usepackage[table]{xcolor}
usepackage{multirow}
definecolor{slg}{gray}{0.95}
% ^^ "super-light gray" -- the builtin 'lightgray' isn't light enough.
begin{document}
Wrong:
rowcolors{1}{white}{slg}
begin{tabular}{c|c|c|c}
A & B & C & D
multirow{2}{*}{Hello!} & foo & bar & 42
& fooo & baar & 13
end{tabular}
bigskip
Right:
begin{tabular}{c|c|c|c}
A & B & C & D
& foo & bar & 42
multirow{-2}{*}{Hello!} & fooo & baar & 13
% ^^ Put it on the odd rows and give it a negative number to span up.
end{tabular}
end{document}
But how can I get this, preferably with the vertical lines intact?
(I cheated and colored the cells manually with cellcolor[gray]{0.95}
)
pdfLaTeX 3.14159265-2.6-1.40.17 (MiKTeX 2.9)
A possible solution is by using the cellcolor
command inside the cell that you want to have a different color. Note that this is not the cell containing the multirow
command but the one above it that you need to place the command in.
documentclass{report}
usepackage[table]{xcolor}
usepackage{multirow}
definecolor{slg}{gray}{0.95}
begin{document}
rowcolors{1}{white}{slg}
Fixed:
begin{tabular}{c|c|c|c}
A & B & C & D
cellcolor{white} & foo & bar & 42
multirow{-2}{*}{Hello!} & fooo & baar & 13
end{tabular}
end{document}
Correct answer by Herthog on July 30, 2021
The latest version of nicematrix
(v 5.8 of 2021-01-01) provides an easy way to do that.
documentclass{report}
usepackage{nicematrix}
usepackage{xcolor}
begin{document}
begin{NiceTabular}{c|c|c|c}
CodeBefore
rowcolors[gray]{1}{}{0.95}[cols=2-*]
Body
A & B & C & D
Block{2-1}{Hello!} & foo & bar & 42
& fooo & baar & 13
end{NiceTabular}
end{document}
You need several compilations (because nicematrix
uses PGF/Tikz nodes).
Answered by F. Pantigny on July 30, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP