发文时间 2021-12-4
最近更新了TexLive的包,发现Tex中比较常用的一个长表格环境 longtabu 无法使用
\begin{longtabu}{<width>}{XXX}
\toprule
a & b & c \\
\bottomrule
\end{longtabu}
报错为 Dimension Too Large
! Dimension Too Large
查找Tabu包的文档、Stackoverflow、GitHub repo 、论坛 发现tabu宏包多年未更新(最后一次更新是2019年,原作者在2011年失去联系,继任者只在2019年更新了一次),已经不能正常使用,TexLive 2021年3月以后的宏包更新会导致longtabu环境无法使用。
找了一圈资料没有找到什么解决方法,故搜索同类的宏包,个人觉得最好用的是 tabularray。其中包含的环境longtblr 可以完美替换 longtabu环境。(注意:旧版本TexLive默认不安装tabularray,新版本默认预装。)
tabularray文档见
https://www.ctan.org/pkg/tabularrayhttps://www.ctan.org/pkg/tabularrayhttps://www.ctan.org/pkg/tabularrayGithub Repohttps://github.com/lvjr/tabularrayhttps://github.com/lvjr/tabularray
主要用法有
类似tabularx的环境
\begin{tblr}[
theme = CustomisableTheme, % 可自定义主题模板(详见文档)
caption = {Table Caption},
label = {tab:table-label},
entry = {Short Caption in Category} % \listoftables 表格目录中出现的名称
]{
width = .9\textwidth,
colspec = {X[1,c,m]|X[2,c,m]}, % 等同于tabularx中的 preamble
stretch = 1.5 % 有效快速的调整行高行间距的命令!!
}
\toptule
% 如需要使用 \toprule \bottomrule \midrule等booktabs内命令
% 一定要在导言区添加 \UseTblrLibrary{booktabs}
a part & b part \\
\midrule
c part & d part \\
\bottomrule
\end{tblr}
类似longtabu和longtable的环境(可跨页)
% 改变跨页时表尾默认的 “接续表”类字样
\DefTblrTemplate{contfoot-text}{default}{接续表}
% 改变跨页后下一页表标题后的 “(续表)”类字样
\DefTblrTemplate{conthead-text}{default}{(续表)}
\begin{longtblr}[
caption = {Caption of long table},
label = {tab:label-of-long-table},
]{
width = \textwidth,
colspec = {p{5em} || X[2,l,m] X[1,c,m]},
rowhead = 1, rowboat = 0, % 每个分页里表头表尾的数量
}
\hline
\SetCell[r=2,c=2]{c} % 直接设置合并单元格 2行2列 水平垂直居中
合并的格子 & ~ & % 合并后的格子必须保留 “&” 并空置
独立的格子1 \\
\cline{2-3}
~ & ~ & 独立的格子2 \\
\hline
\end{longtblr}
使用后感觉亮点在
- 合并单元格更方便(只需要在第一格内声明\SetCell[r=row_num, c=col_num]{<align>}即可)
- 能简便的调整表格行高 (行间距)(在环境Key中设置 stretch = 倍数 )
- 表格属性设置用 Key = Value 格式,类似Json的格式书写,更符合主流编程语言的习惯
- 表格对文字垂直居中水平居中等对齐方式的支持更完美
- 保留了Tabu包中按比例自适应调整列宽的方便方法 X[2, c, m],并且额外添加在括号中设置列宽的功能
- 能方便的设置表元素颜色
- 可以设置表格Theme模板,每次创建表格直接引用模板即可
部分文档: