返回使用 xTable 绘制表格
xtable 更适用于复杂的大表格。
xtable 的使用整体和 btable 类似,所有命令也是成对出现,不过用 start 代表开始,stop 代表结束。 \startxtable开始一个表格,\stopxtable结束表格。 \startxrow开始新的一行,\stopxrow结束当前行。 \startxcell开始新的单元格或一列,\stopxcell结束单元格或当前列。 简单的表格示例:
\startxtable \startxrow \startxcell 年份 \stopxcell \startxcell 产品 \stopxcell \startxcell 销量 \stopxcell \stopxrow \startxrow \startxcell 2021 \stopxcell \startxcell 柚子 \stopxcell \startxcell 4500 \stopxcell \stopxrow …… \stopxtable
xtable 还支持成列的添加表格数据,单元格内数据加载仍然使用xcell,但使用 xcolumn 包括每列的内容。
\startxtable \startxcolumn \startxcell 年份 \stopxcell \startxcell 2021 \stopxcell \startxcell 2021 \stopxcell  \startxcell 2023 \stopxcell  \startxcell 2024 \stopxcell \stopxcolumn …… \stopxtable

样式更改

xtable 同样也继承 setupframed 的特性,所以他和 btable 一样可以灵活的对表格整行,单个单元格进行装饰。整行的样式设置可以把参数放在\startxrow后面。单个单元格的样式设置放在\startxcell后面。
\startxtable \startxrow[background=color,backgroundcolor=gray] \startxcell[width=5em] 年份 \stopxcell \startxcell[width=5em] 产品 \stopxcell \startxcell[width=5em] 销量 \stopxcell \stopxrow \startxrow \startxcell 2021 \stopxcell \startxcell 柚子 \stopxcell \startxcell 4500 \stopxcell \stopxrow …… \stopxtable
对于会被重复使用的样式,可以通过 setupxtable 来定义一个可被重读使用的元素,然后在需要的 xrow 或者 xcell 后面加上 [name] 来应用到单元格上。
\setupxtable[highlight] [background=color,backgroundcolor=darkred,foregroundcolor=white] \setupxtable[highlight2] [background=color,backgroundcolor=darkgreen,foregroundcolor=white] …… \startxrow \startxcell[highlight] 2021 \stopxcell \startxcell 柚子 \stopxcell \startxcell[highlight2] 4500 \stopxcell \stopxrow ……

行间距和列间距

和 bTable 一样,行间距通过spaceinbetween设置,列间距通过columndistance设置。
\startxtable[spaceinbetween=3pt] …… \stopxtable
\startxtable[columndistance=3pt] …… \stopxtable

单元格的合并

元格需要合并行或者合并列时,通过 nr 指定要合并的行,nc 指定要合并的列,应用在 xcell 上。
\startxtable \startxrow \startxcell 超市 \stopxcell \startxcell 产品 \stopxcell \startxcell 销量 \stopxcell  \stopxrow \startxrow \startxcell[nr=2]祥泰隆 \stopxcell   \startxcell 柚子 \stopxcell \startxcell 4500 \stopxcell \stopxrow \startxrow                        \startxcell 水蜜桃 \stopxcell \startxcell 480 \stopxcell \stopxrow \startxrow \startxcell[nr=2] 欧德亚 \stopxcell  \startxcell 柠檬 \stopxcell \startxcell 50 \stopxcell \stopxrow \startxrow                        \startxcell 蓝莓 \stopxcell \startxcell 930 \stopxcell \stopxrow \startxrow[background=color,backgroundcolor=darkgray,foregroundcolor=white] \startxcell[nc=3,align=flushright] 总计:5960 \stopxcell \stopxrow \stopxtable

表格的嵌套

在 xtable 里可以再定义新的 xtable 来实现更复杂的内容展示。
\startxtable \startxrow \startxcell 年份 \stopxcell \startxcell[width=2cm] 产品 \stopxcell \startxcell 销量 \stopxcell \stopxrow \startxrow \startxcell 2021 \stopxcell \startxcell \startxtable[frame=off] \startxrow \startxcell[bottomframe=on,width=max] 西柚 \stopxcell \stopxrow \startxrow \startxcell 红柚 \stopxcell \stopxrow \stopxtable \stopxcell \startxcell 4500 \stopxcell \stopxrow …… \stopxtable

表头重复显示

表头的重复显示和 btable 类似,通过xtablehead设置表头内容和样式,xtablenext设置拆分表的表头内容和样式。
\startxtable[split=repeat] \startxtablehead \startxrow[background=color,backgroundcolor=gray,foregroundcolor=black] \startxcell  年份 \stopxcell \startxcell  产品 \stopxcell \startxcell  销量 \stopxcell \stopxrow \stopxtablehead \startxtablenext \startxrow [background=color,backgroundcolor=gray,foregroundcolor=black] \startxcell  年份(续) \stopxcell \startxcell  产品(续) \stopxcell \startxcell  销量(续) \stopxcell \stopxrow \stopxtablenext …… \stopxtable
©2024 All Rights 石家庄市友文信息技术有限责任公司冀ICP备2023031763号