我遵循了几个建议,在表格行之间添加时删除了额外的空格hrule
。我有以下代码:
\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}
答案1
您可以使用\cmidrule
from booktabs
,它可以使用修剪参数,如下所示:
\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}
答案2
我的问题的答案是一个不太明确的记录选项(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}