0

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

0

You can use\cmidrule 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

  • Hmmm... this seems to works although not my preferred solution. The major problem with this is that I need to know the amount of column in advance. Since I automatically generate the code this is a non-trivial approach. AND I need to stretch the line anyway over all columns. Isn't there a simpler solution which doesn't require to know the no of columns in advance? – LeO Nov 26 '20 at 11:45
  • Unfortunately, among the rules of booktabs, only \cmidrule has the trimming functionality. Maybe patching the code for \midrule might add this functionality. I'll try to see whether it's possible. – Bernard Nov 26 '20 at 13:23
  • A side note: I didn't test in details. Nevertheless I know I have as well nested tables - which might influence the width of a table. So, my point here is that its not necessarily the \textwidth which should be used. Just a side note in case of a fix! – LeO Nov 26 '20 at 13:51
  • Could you post an example code? Note nested tabulars are often not necessary, as there are alternative solutions. – Bernard Nov 26 '20 at 14:19
  • tex.stackexchange.com/a/571466/48642 But plz: Don't blame me cuz as mentioned before - they are generated automatically. If the ruler finally doesn't apply for nested I don't care so much. It's just in the case an easy adaption is possible. BTW: In the nested tables \midrule works fine. – LeO Nov 26 '20 at 15:49
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.