我需要在文档中插入一个 2 列长的表格,并在第二列的每个单元格中输入大量文本。但最终结果是表格占据了文档的 6 页。
我一直在尝试减小表格内文本的字体大小,但到目前为止,我发现的唯一解决方案是也减小表格标题的大小,这看起来很奇怪。
我尝试过的解决方案之一是这,但由于某种我无法理解的原因,它没有按预期工作。
目前,我使用的解决方案是longtblr
在里面插入环境\begingroup
,然后在那里设置文本的字体大小。
有没有办法只调整单元格或某些特定行中的文本大小,同时保持标题的原始字体大小?
梅威瑟:
\documentclass[12pt, a4paper, twoside, english]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{array,booktabs}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{xcolor}
\begin{document}
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
\begingroup
\fontsize{8pt}{8pt}\selectfont
\begin{longtblr}[
caption = {Caption of the table.},
label = {tab:label},
]{
Q[c,m]|X[l,m]
}
\hline
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
row & some relatively long description so that the other entries can showboat their floatiness
\end{longtblr}
\endgroup
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
\end{document}
答案1
- 给定链接中问题的答案正是您在问题标题中要求的。
- 如果您遇到问题,不清楚表格解决方案如何使用,请阅读
tabularray
包或在这里询问,您在哪部分代码(大概是表格序言中的设置)遇到了问题。 - 表格的背景和目的尚不清楚,但任何类型的表格通常都包含列标题,在长表格的情况下,列标题会在表格所跨越的每一页上重复出现。
- 从印刷的角度考虑,建议整个表格采用相同的字体大小(建议表格仍然可读,字体不要小于
\footnoteseize
)。 - 如果使用给定链接中提出的解决方案的表格不能充分减少表格大小,您仍然有两个选项可以将其稍微挤压一点:
- 减少
rowsep
,例如通过设置rowsep = 1pt
或rowsep = 0.5pt
- 减少
\baselineskip
单元格文本,例如使用cells = {font=\footnotesize\linespread{0.84}\selectfont}
- 减少
- 看看以下解决方案(我认为它更“专业”)是否可以接受:
\documentclass[12pt, a4paper, twoside, english]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{microtype} % added for better spacing of text
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\SetTblrStyle{firstfoot,middlefoot}{\footnotesize\itshape}
\usepackage{lipsum}
\begin{document}
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
\begin{longtblr}[
caption = {Caption of the table.},
label = {tab:label},
]{colspec = {Q[c] X[j]},
cells = {font=\footnotesize\linespread{0.84}\selectfont},
rowsep = 1pt,
rowhead = 1
}
\toprule
item & Description \\
\midrule
row & \lipsum[66] \\
row & some relatively long description so that the other entries can showboat their floatiness\\
row & \lipsum[1] \\
row & \lipsum[2] \\
row & \lipsum[3] \\
row & \lipsum[4] \\
row & \lipsum[5] \\
row & \lipsum[7] \\
row & \lipsum[66] \\
row & \lipsum[66] \\
row & \lipsum[66] \\
\bottomrule
\end{longtblr}
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
\end{document}
但是,如果您更喜欢更丑陋的解决方案,即仅在特定单元格中字体大小较小,那么请遵循其他答案中的主张,即通过在这些单元格中插入来本地设置此单元格的字体大小
\SetCell{font=\tiny} % or any other font size
题外话:在任何类型的表中,行都应相应终止。 在您的例子中,您应该在每行末尾添加\\
。
答案2
在 MWE 中,每行末尾都有一个小错误,这会使文档的编译看起来有点不对劲。对于tabularray
,所有行都必须以 结尾\\
,因此这样。
row & some relatively long description so that the other entries can showboat their floatiness
應該這樣!
row & some relatively long description so that the other entries can showboat their floatiness \\
现在,我假设您的实际文档中并非如此。要强制列使用特定的列宽,您只需wd
在使用Q
列宏时添加规范,因此,在此示例中,第 18 行应如下所示:
colspec = {Q[c,m]|Q[l,m,wd=10cm]}
该colspec
命令只是告诉包这应该只会影响列设置,这样写很好,因为稍后您可能需要编辑该字段中不会影响列的其他内容。 “ ”选项强制该列的单元格使用该值作为最大文本框宽度,因此请随意更改它!此外,正如您所问的,您可以使用选项通过宏wd
控制列字体大小,如下所示:Q
font
colspec={Q[c,m]|Q[l,m,wd=10cm,font=\tiny]}
这会使该列上的文本变小!当然,您可以通过\SetCell
内容内部执行此操作以仅影响一个单元格,但这取决于您。
使用文档进行更多测试,我认为唯一的错误是缺少\\
行,但希望这些额外的信息能帮助您为烹饪的食物增添更多风味!希望这能有所帮助!