TransWikia.com

Rowcolor in xltabular and whitespace

TeX - LaTeX Asked on December 31, 2020

I followed several suggestions to get rid of the additional whitespace when adding a hrule between table rows. I have the following code:

documentclass[a4paper,11pt]{article}
usepackage[a4paper, margin=2.5cm]{geometry} 
usepackage[shorthands=off,bidi=basic,english, ngerman]{babel}
usepackage[table]{xcolor} 

usepackage{xltabular} % for tables with long lines & long tables (over >1 page)
usepackage{luacolor,lua-ul} %for usage of style attributes - background color

%------regular rule -------
makeatletter
newcommand{tablehline}{%
    noalign {ifnum 0=`}fi hrule height 1pt
    futurelet reserved@a @xhline
}
makeatother
%-------------------------

begin{document}
begin{xltabular}{textwidth}{@{} X  X  X @{}}
tablehline
rowcolor[HTML]{b96ad9} 
textbf{Firstname} &  
textbf{Lastname} &  
textbf{Age} 
tablehline

cellcolor[HTML]{b96ad9}Jill &  
Smith &  
50 
tablehline

Eve &  
cellcolor[HTML]{b96ad9}Jackson &  
94 
tablehline

John1 &  
Doe &  
80 
tablehline

end{xltabular}

end{document}

The whole code works quite well up to the point when introducing @{} in the table. Obviously the ruler is not extended to this area. Is there a way to extend the ruler as well?
Ruler not extending

2 Answers

The answer to my question is a more less not clearly documented option (lr)

documentclass[a4paper,11pt]{article}
usepackage[margin=2.5cm]{geometry}
usepackage[shorthands=off, bidi=basic, english, ngerman]{babel}%
usepackage[table]{xcolor}
usepackage{booktabs}
aboverulesep=0pt
belowrulesep=0pt
cmidrulekern=-tabcolsep

usepackage{xltabular} % for tables with long lines & long tables (over >1 page)
usepackage{luacolor,lua-ul} %for usage of style attributes - background color

begin{document}

begin{xltabular}{textwidth}{@{} X X X @{}}
cmidrule[1pt](lr){1-3}

rowcolor[HTML]{b96ad9}
textbf{Firstname} &
textbf{Lastname} &
textbf{Age} 
bottomrule(lr)
cellcolor[HTML]{b96ad9}Jill &
Smith &
50 
midrule(lr)
Eve &
cellcolor[HTML]{b96ad9}Jackson &
94 
midrule(lr)

John1 &
Doe &
80 
midrule(lr)
end{xltabular}
end{document} 

enter image description here

Correct answer by LeO on December 31, 2020

You can usecmidrule from booktabs, which can use a trimming argument, like this:

documentclass[a4paper,11pt]{article}
usepackage[margin=2.5cm]{geometry}
usepackage[shorthands=off, bidi=basic, english, ngerman]{babel}%
usepackage[table]{xcolor}
usepackage{booktabs}
usepackage{xltabular} % for tables with long lines & long tables (over >1 page)
usepackage{luacolor,lua-ul} %for usage of style attributes - background color
%------regular rule -------
makeatletter
newcommand{tablehline}{%
    noalign {ifnum 0=`}fi hrule height 1pt
    futurelet reserved@a @xhline
}
makeatother
%-------------------------
begin{document}

{aboverulesep=0pt
belowrulesep=0pt
cmidrulekern=-tabcolsep
begin{xltabular}{textwidth}{@{} X X X @{}}
%tablehline
cmidrule[1pt](lr){1-3}
rowcolor[HTML]{b96ad9}
textbf{Firstname} &
textbf{Lastname} &
textbf{Age} 
%tablehline
cmidrule[1pt](lr){1-3}
cellcolor[HTML]{b96ad9}Jill &
Smith &
50 
%tablehline
cmidrule[1pt](lr){1-3}
Eve &
cellcolor[HTML]{b96ad9}Jackson &
94 
tablehline

John1 &
Doe &
80 
tablehline
end{xltabular}}

end{document} 

enter image description here

Answered by Bernard on December 31, 2020

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