假设我有一个表格,它不适合一页。假设我不想使用任何特殊的表格类型,但想通过使用 -command 来解决问题\resizebox
并保持我的比例。
如果使用\resizebox{\texwidth}{!}{...}
表格合适,那么我的问题就解决了。但如果表格仍然太长,我的直觉是使用\resizebox{!}{\textheight}{...}
。为标题留出一些空间,我必须将高度调整到大约,0.9\textheight
以确保单行标题。但在我的例子中,我必须将高度调整到大约。0.48\textheight
以消除所有警告并使表格适合页面。这对我来说似乎很奇怪。我遗漏了什么?
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}[htbp]
\centering
% \resizebox{\textwidth}{!}{
\resizebox{!}{0.48\textheight}{
\begin{tabular}{|lll|}\hline
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\
TextTextTextTextTextText & TextTextTextTextText & TextTextTextTextText\\ \hline
\end{tabular}}
\caption{test}
\end{table}
\end{document}
答案1
你遇到了一个常见问题,混淆了高度和总高TeX 中的东西。出于某种原因,这也让我感到惊讶,表格的基线是表格的中间,因此下半部分是深度生成的 TeX 框。\resizebox
缩放框高度,而不是总高(高度+深度)为给定值。要缩放总高度,请使用版本*
。您还可以使用\dimexpr
(另请参阅在 LaTeX 源代码中使用距离值进行数学运算)或calc
包从高度中减去例如两条线:
\resizebox*{!}{\dimexpr\textheight-2\baselineskip\relax}{%
还要注意,将大型表格放在宏参数中效率非常低,并且不允许\verb
在表格中使用等。您可以使用相对较新的包(由我编写)中的\adjustbox
宏或环境来缩放任何内容。两者都将内容读取为框而不是参数,并避免了上述缺点:adjustbox
adjustbox
\usepackage{adjustbox}
% [...]
\begin{adjustbox}{totalheight=\textheight-2\baselineskip}
\begin{tabular}{...}
...
\end{tabular}
\end{adjustbox}
环境adjustbox
和宏接受\includegraphics
宏的所有选项。这包括height
和totalheight
。
请注意,adjustbox
使用pgfmath
来解析给定的尺寸,因此您可以使用此包支持的所有数学运算。但是,不要\dimexpr
直接使用,因为它不支持pgfmath
。