TransWikia.com

rowcolor too large when removing space on rows

TeX - LaTeX Asked on March 24, 2021

I am a LaTeX beginner and facing an issue that I can’t seem to find the answer for… I am creating a table (using booktabs but my issue also occurs when not using the package), and whenever I remove the space on the edges of the table (with @{}) and try to colour individual rows at the same time, the space taken by the colour is wider than the table. See the following example:

usepackage{array}
usepackage{colortbl}
usepackage[table,xcdraw]{xcolor}
% [...]


fbox{begin{tabular}{@{}ll@{}}
foo & bar
rowcolor[HTML]{BFBFBF} bar & foo
end{tabular}}

Which results in the following:

rowcolor is too wide!

Thanks in advance for any help/pointer!

2 Answers

You could use NiceTabular from the nicematrix package instead:

enter image description here

documentclass{article}
usepackage[table,xcdraw]{xcolor}

definecolor{mygray}{HTML}{BFBFBF}

usepackage{nicematrix}
begin{document}


fbox{begin{NiceTabular}{@{}ll@{}}[code-before=rowcolor{mygray}{2}]
foo & bar
 bar & foo
end{NiceTabular}}

end{document}

Answered by leandriis on March 24, 2021

I suggest setting fboxsep to $0$ instead, and keeping the spaces at both ends of the table, loading cellspace for the vertical spacing at the top and bottom of the table:

documentclass{article}
usepackage{array}
usepackage[table,xcdraw]{xcolor}
usepackage{cellspace}
setlength{cellspacetoplimit}{4pt}
setlength{cellspacebottomlimit}{4pt}
% [...]
begin{document}

{setlength{fboxsep}{0pt}
fbox{%
begin{tabular}{Sll}
foo & bar
rowcolor[HTML]{BFBFBF} bar & foo
end{tabular}}
}
end{document} 

enter image description here

Answered by Bernard on March 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP