我有一个tabularray
longtblr
由多组行组成的表格,这些行之间由额外的垂直空间隔开。当一个组位于表格页面的末尾时,它会在该组和底部之间产生难看的空间\hline
。
当页面底部出现多余的垂直空间时,有没有办法将其折叠起来?
本示例代码:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{longtblr}{colspec=lX,width=\textwidth,rowsep=0pt}
\hline
Head \\
\hline
\multicolumn{2}{l}{Group 1} \\*
& 1.1 \\[2ex]
\multicolumn{2}{l}{Group 2} \\*
& 2.1 \\[2ex]
\multicolumn{2}{l}{Group 3} \\*
& 3.1 \\[2ex]
\multicolumn{2}{l}{Group 4} \\*
& 4.1 \\[2ex]
\multicolumn{2}{l}{Group 5} \\*
& 5.1 \\[2ex]
\multicolumn{2}{l}{Group 6} \\*
& 6.1 \\[2ex]
\multicolumn{2}{l}{Group 7} \\*
& 7.1 \\[2ex]
\multicolumn{2}{l}{Group 8} \\*
& 8.1 \\[2ex]
\multicolumn{2}{l}{Group 9} \\*
& 9.1 \\[2ex]
\multicolumn{2}{l}{Group 10} \\*
& 10.1 \\[2ex]
\multicolumn{2}{l}{Group 11} \\*
& 1.1 \\[2ex]
\multicolumn{2}{l}{Group 12} \\*
& 2.1 \\[2ex]
\multicolumn{2}{l}{Group 13} \\*
& 3.1 \\[2ex]
\multicolumn{2}{l}{Group 14} \\*
& 4.1 \\[2ex]
\multicolumn{2}{l}{Group 15} \\*
& 5.1 \\[2ex]
\multicolumn{2}{l}{Group 16} \\*
& 6.1 \\[2ex]
\multicolumn{2}{l}{Group 17} \\*
& 7.1 \\[2ex]
\multicolumn{2}{l}{Group 18} \\*
& 8.1 \\[2ex]
\multicolumn{2}{l}{Group 19} \\*
& 9.1 \\
\hline
\end{longtblr}
\end{document}
结果是:
答案1
(1)您可以用白色水平线替换行下方的垂直空间;分页符处的水平线将被删除。
(2)您可以\multicolumn
用\SetCell
;替换,\multicolumn
命令将在 2022 版本中删除。
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{longtblr}{colspec=lX,width=\textwidth,rowsep=0pt}
\hline
Head \\
\hline
\SetCell[c=2]{l} Group 1 \\*
& 1.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 2 \\*
& 2.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 3 \\*
& 3.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 4 \\*
& 4.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 5 \\*
& 5.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 6 \\*
& 6.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 7 \\*
& 7.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 8 \\*
& 8.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 9 \\*
& 9.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 10 \\*
& 10.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 11 \\*
& 1.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 12 \\*
& 2.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 13 \\*
& 3.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 14 \\*
& 4.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 15 \\*
& 5.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 16 \\*
& 6.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 17 \\*
& 7.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 18 \\*
& 8.1 \\
\hline[white,2ex]
\SetCell[c=2]{l} Group 19 \\*
& 9.1 \\
\hline
\end{longtblr}
\end{document}
答案2
看看以下 MWE 是否给出了您想要的内容:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrStyle{caption-tag}{font=\bfseries}
\ExplSyntaxOn
\NewChildSelector{eachtwo}
{
\int_step_inline:nnnn {2}{2}{\l_tblr_childs_total_tl}
{ \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
\ExplSyntaxOff
\begin{document}
\begin{longtblr}[
caption = {Does your table has a caption?}
]
{
colspec = {lX},
rowsep = 0pt,
row{eachtwo} = {abovesep=2ex},
row{1} = {font=\bfseries, rowsep=2pt},
row{2} = {abovesep=2pt},
}
% table body
\toprule
Head & \\
\midrule
\SetCell[c=2]{l} {Group 1} \\*
& 1.1 \\
\SetCell[c=2]{l} {Group 2} \\*
& 2.1 \\
\SetCell[c=2]{l} {Group 3} \\*
& 3.1 \\
\SetCell[c=2]{l} {Group 4} \\*
& 4.1 \\
\SetCell[c=2]{l} {Group 5} \\*
& 5.1 \\
\SetCell[c=2]{l} {Group 6} \\*
& 6.1 \\
\SetCell[c=2]{l} {Group 7} \\*
& 7.1 \\
\SetCell[c=2]{l} {Group 8} \\*
& 8.1 \\
\SetCell[c=2]{l} {Group 9} \\*
& 9.1 \\
\SetCell[c=2]{l} {Group 10} \\*
& 10.1 \\
\SetCell[c=2]{l} {Group 11} \\*
& 1.1 \\
\SetCell[c=2]{l} {Group 12} \\*
& 2.1 \\
\SetCell[c=2]{l} {Group 13} \\*
& 3.1 \\
\SetCell[c=2]{l} {Group 14} \\*
& 4.1 \\
\SetCell[c=2]{l} {Group 15} \\*
& 5.1 \\
\SetCell[c=2]{l} {Group 16} \\*
& 6.1 \\
\SetCell[c=2]{l} {Group 17} \\*
& 7.1 \\
\SetCell[c=2]{l} {Group 18} \\*
& 8.1 \\
\SetCell[c=2]{l} {Group 19} \\*
& 9.1 \\
\bottomrule
\end{longtblr}
\end{document}
编辑: 从 OP 评论中我得出结论,上面的 MWE 不是他想要的。由于问题不清楚,问题是什么,现在我猜,他想要的可能是下面的 MWE。
在 MWE 中,前四行添加了多列单元格的可能内容和第一列的可能内容的变化。
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrStyle{caption-tag}{font=\bfseries}
\usepackage{lipsum}
\begin{document}
\begin{longtblr}[
caption = {Does your table has a caption?}
]
{
colspec = {l X[font=\linespread{0.84}\selectfont]},
rowsep = 1pt,
row{1} = {font=\bfseries, rowsep=2pt},
}
% table body
\toprule
Head & some text \\*
\midrule
\SetCell[c=2]{l} Title of group 1 \\*
a & \lipsum[1][1-2] \\
b & \lipsum[1][3-4] \\
c & \lipsum[1][5] \\
\addlinespace
\SetCell[c=2]{font=\bfseries} Title of Group 2
(in boldface, if you like) \\*
a & 2.1 \\
b & 2.1 \\
\addlinespace
\SetCell[c=2]{c} Title of Group 3 (in center, if you like) \\*
a & 3.1 \\
b & 3.2 \\
c & 3.3 \\
d & 3.4 \\
e & 3.5 \\
f & 3.6 \\
\addlinespace
\SetCell[c=2]{l} Title Group 4 \\*
content of cell is unknown
& \lipsum[66] \\
\addlinespace
\SetCell[c=2]{l} Title Group 5 \\*
& 5.1 \\
& 5.2 \\
\addlinespace
\SetCell[c=2]{l} Title Group 6 \\*
& 6.1 \\
\addlinespace
\SetCell[c=2]{l} Title Group 7 \\*
& 7.1 \\
& 7.2 \\
& 7.3 \\
\addlinespace
\SetCell[c=2]{l} Title Group 8 \\*
& 8.1 \\
& 8.2 \\
\addlinespace
\SetCell[c=2]{l} Title Group 9 \\*
& 9.1 \\
& 9.1 \\
\addlinespace
\SetCell[c=2]{l} Title Group 10 \\*
& 10.1 \\
& 10.2 \\
& 10.3 \\
\addlinespace
\SetCell[c=2]{l} Title Group 11 \\*
& 11.1 \\
& 11.2 \\
\addlinespace
\SetCell[c=2]{l} Title Group 12 \\*
& 12.1 \\
\addlinespace
\SetCell[c=2]{l} Title Group 13 \\*
& 13.1 \\
& 13.1 \\
& 13.1 \\
\addlinespace
\SetCell[c=2]{l} Title Group 14 \\*
& 14.1 \\
\addlinespace
\SetCell[c=2]{l} Title Group 15 \\*
& 15.1 \\
& 15.2 \\
& 15.3 \\
& 15.4 \\
\addlinespace
\SetCell[c=2]{l} Title Group 16 \\*
& 16.1 \\
\bottomrule
\end{longtblr}
\end{document}