我有一个想要插入到页面上的表格,但至少需要满足以下一个条件(也可能是两个条件):
桌子太宽的以适应文本块或页面。也就是说,我超出了一些水平的限制。
桌子太高的以适应文本块或页面。也就是说,我超出了一些垂直的限制。
我有什么办法可以让这张桌子放得下?如果它放不下,无论我怎么努力,还有其他什么办法吗?
答案1
首先,让我们来明确一下我们使用“表”这个术语时指的是什么。典型的table
环境是漂浮,并且可以包含任何内容:一段文本、一张图片,甚至一个tabular
。本文将讨论如何使用后者 - a tabular
- 以及如何调整它。讨论也适用于array
结构,因为它们提供了数学模拟tabular
。
考虑阅读如何影响 LaTeX 中图形和表格等浮动环境的位置?如果你感兴趣漂浮- 特定的展示位置。
其次,要明白 atabular
是静态的二维结构。因此,它可能最适合表示二维(例如年龄X性别, 或者地区X类型)因此,如果不“仔细”呈现,表示二维以上的东西可能本身就存在问题,因为要制表的元素数量会扩大几何地. 如果你要呈现(比如说)三个维度的信息,比如说年龄,性别和种族并且表格不适合,也许可以考虑将这张单表拆分tabular
成年龄和性别对于每个种族请记住,表格应该扩展或简化信息的消化,因此如果表格的表示看起来复杂、密集或令人困惑,那么分成更基本的组件可能是最好的选择。
1. 我的表格tabular
太宽了。我该怎么做才能让它适合?
以下是可供考虑的可能选项(无特定顺序):
- 如果您要呈现具有大(宽)列标题的数据,请考虑堆叠或者缩写这些可以折叠过宽的列:
\documentclass{article}
\usepackage{makecell}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide. \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
\end{tabular}
\medskip
% Condense column headers using abbreviations or acronyms
\begin{tabular}{ *{12}{c} }
This&is&a&\texttt{tbl}&with&twelve&cols&that&is&just&too&wide. \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\[.5\normalbaselineskip]
\multicolumn{12}{l}{%
\footnotesize \texttt{tbl}: \texttt{tabular} title; cols: column title}
\end{tabular}
\bigskip
\begin{tabular}{ *{3}{c} }
This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% Condense column headers via stacking
\begin{tabular}{ *{3}{c} }
This is & & too wide \\
a \texttt{tabular} with & three columns that & to fit \\
& is just & in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% Condense column headers via stacking
\begin{tabular}{ *{3}{c} }
\makecell[b]{This is \\ a \texttt{tabular} with} &
\makecell[t]{three columns that \\ is just} &
\makecell{too wide \\ to fit \\ in \texttt{\string\textwidth}.} \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% Condense column headers via stacking in a paragraph-style column
\begin{tabular}{ *{3}{c} }
\multicolumn{1}{p{60pt}}{\centering This is a \texttt{tabular} with} &
\multicolumn{1}{p{7em}}{\raggedleft three columns that is just} &
\multicolumn{1}{p{3cm}}{\raggedright too wide to fit in \texttt{\string\textwidth}.} \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
手动堆叠可能很繁琐。将列标题设置为固定宽度p{<len>}
列是一种提供自动换行方式的方法(如上所示)。
- 使用 aragraph-style 列规范时,可以允许列条目自然换行
p
。此p{<len>}
-style 列在 处换行<len>
。如果您不知道<len>
应该怎么做,tabularx
可以通过其灵活的X
列来帮助:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{3}{c} }
This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabular}
\medskip
% tabularx provides a fixed-width table with flexible columns
\begin{tabularx}{\textwidth}{ c X >{\raggedright\arraybackslash}X }
This is a \texttt{tabular} with&three columns that is just&too wide to fit in \texttt{\string\textwidth}. \\
\hline
1 2 3 4 & 5 6 7 8 & 9 10 11 12
\end{tabularx}
\caption{This is a table caption.}
\end{table}
\end{document}
在 -columns 内进行对齐换行X
可能会导致出现过满\hbox
警告,可以使用设置来避免这种情况\raggedright
。由于tabularx
加载array
,>{<prefix>}
可以添加列前缀。
tabulary
提供了类似的界面,在这方面也可能有帮助。
- 标头回转也可能提供一些水平减少:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\hd}{\rotatebox{60}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide. \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
\end{tabular}
\bigskip
% Condense column headers using rotation
\begin{tabular}{ *{12}{c} }
\hd{This}&\hd{is}&\hd{a}&\hd{\texttt{tabular}}&\hd{with}&\hd{twelve}&
\hd{columns}&\hd{that}&\hd{is}&\hd{just}&\hd{too}&\hd{wide.} \\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
旋转格式在视觉上相当极端,应谨慎使用。
- 尝试水平适配的最佳方法可能是打破
tabular
较小、宽度适配的tabular
s。从视觉上看,这是最不具侵入性的(一般而言),并且可能将信息公开,以便读者更好地理解:
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\begin{tabular}{ *{6}{c} }
1 & 2 & 3 & 4 & 5 & 6 \\
\hline
This & is & a & \texttt{tabular} & with & twelve \\
\\
7 & 8 & 9 & 10 & 11 & 12 \\
\hline
columns & that & is & just & too & wide.
\end{tabular}
\bigskip
\begin{tabular}{ *{6}{c} }
1 & 2 & 3 & 4 & 5 & 6 \\
\hline
This & is & a & \texttt{tabular} & with & twelve
\end{tabular}
\medskip
\begin{tabular}{ *{6}{c} }
7 & 8 & 9 & 10 & 11 & 12 \\
\hline
columns & that & is & just & too & wide.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
- 考虑删除水平内容,使其适合所需的宽度。您可以手动删除内容,尽管这对于较大的
tabular
s 来说可能很乏味。但是,如果您不想删除内容但仍想删除列,请阅读删除列的最简单方法?。
\documentclass{article}
% https://tex.stackexchange.com/a/16607/5764
\usepackage{array}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
% Drop/Hide column 10
\begin{tabular}{ *{9}{c} H *{2}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
- 考虑减少列之间的水平间距。默认文档类定义
\tabcolsep
为6pt
。对于array
,使用的长度为 ,\arraycolsep
默认值为5pt
。这可能超出您的需要。对于多列tabular
,减少\tabcolsep
可以为您节省宝贵的分数。
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\begingroup
\setlength{\tabcolsep}{0.75\tabcolsep}% Reduce \tabcolsep by 25%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\endgroup
\caption{This is a table caption.}
\end{table}
\end{document}
可能需要将变更的范围限制为\tabcolsep
,因此使用分组调整\setlength
(通过\begingroup
...\endgroup
或{
... }
)。
- 考虑减小所用字体的大小。如果您的文档
tabular
使用默认字体,也许或可能使其适合:\normalsize
\small
\footnotesize
\documentclass{article}
\begin{document}
\begin{table}
\centering
% This tabular is too wide
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\begingroup
\footnotesize% Change to smaller font from \normalsize
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\endgroup
\caption{This is a table caption.}
\end{table}
\end{document}
看LaTeX 文档的默认字体大小是多少?和\Large 等字体大小是多少点(pt)?有关字体和字体大小的讨论。
可能需要将更改的范围限制在字体上,因此使用分组(通过\begingroup
...\endgroup
或{
... }
)。
- 对于太宽的
tabular
表格,你可以调整整个表格的大小以适合你的范围水平使用\resizebox{<width>}{<height>}{<tabular>}
最多或(<width>
参见\linewidth
\textwidth
\textwidth、\linewidth 和 \hsize 之间的区别!
)。的符号<height>
将确保调整大小的纵横比保持不变。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
% \resizebox{<width>}{<height>}{<tabular>}
\resizebox{\linewidth}{!}{%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
缩小tabular
规模全部内容...包括文本。如果缩小的因素足够小,文档中使用的字体和缩放后的字体之间可能不会有明显的差异tabular
。
- 也许你已经承认
tabular
能与边距对齐,因为上述任何更改都不足以满足您的需求。但是,默认情况下\centering
不会tabular
以居中方式设置,因此您可以将tabular
内部设置\makebox[<width>]
为足够小<width>
(小于\linewidth
),这将自动将其置于边距范围内居中(请参阅如何让太宽的表格居中?):
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
% This tabular is still too wide, but we'll keep it as-is...
\makebox[\textwidth]{%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
- 您可以将表格旋转 90 度(顺时针或逆时针),将其侧放。通常,页面的高度大于宽度,这样可能会合适
tabular
。然而,这将是一个极端的调整,因为你要求观众调整他们的视角,有些人可能不喜欢这种水平(从左到右)和垂直(从下到上)设置之间的切换:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\bigskip
\rotatebox{90}{%
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
graphicx
's\rotatebox{<angle>}{<tabular>}
用于<tabular>
度数旋转<angle>
。
上面的例子旋转tabular
仅有的,标题保留在原处。如果您想旋转整个漂浮- 包含标题,您可以使用sidewaystable
(由rotating
包裹):
\documentclass{article}
\usepackage{rotating}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\begin{sidewaystable}
\centering
\begin{tabular}{ *{12}{c} }
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 \\
\hline
This&is&a&\texttt{tabular}&with&twelve&columns&that&is&just&too&wide.
\end{tabular}
\caption{This is a table caption.}
\end{sidewaystable}
\end{document}
请注意,假设sidewaystable
您的桌子相当宽的因此将占据大部分文本块高度在旋转期间。因此,默认行为是将其放置在其自己的页面上。
2. 我的桌子tabular
太高了。我该怎么做才能把它放得下?
上面列出的许多相同程序都可以应用垂直为了调整您的tabular
布局,例如更改字体、旋转或手动将内容分成多个tabular
;下面列出了一些建议。
\arraystretch
用于拉伸(或收缩) 中的每一行tabular
。也许您\documentclass
增加了这个值。您可以使用以下方法进行调整\renewcommand
:
\documentclass{article}
\begin{document}
\begin{table}
\begin{minipage}{0.3333\linewidth}
\centering
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\end{minipage}%
\begin{minipage}{0.3333\linewidth}
\centering
\renewcommand{\arraystretch}{1}
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\end{minipage}%
\begin{minipage}{0.3333\linewidth}
\centering
\renewcommand{\arraystretch}{0.8}
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\end{minipage}
\caption{This is a table caption.}
\end{table}
\end{document}
- 考虑切出大块的行并水平堆叠它们,而不是以垂直方式保存内容。
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\bigskip
\begin{tabular}{ c c @{\hspace{2em}} c c }
1&This & 1&This \\
\hline
2&is & 8&that \\
3&a & 9&is \\
4&\texttt{tabular} & 10&just \\
5&with & 11&too \\
6&twelve & 12&tall. \\
7&rows
\end{tabular}
\bigskip
\begin{tabular}[t]{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\ 7&rows
\end{tabular}\hspace{2em}%
\begin{tabular}[t]{ c c }
1&This \\
\hline
8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}
\caption{This is a table caption.}
\end{table}
\end{document}
- 减小字体大小也会减小行高,从而减小垂直跨度
tabular
:
\documentclass{article}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}%
\hspace{2em}%
\begingroup
\small% Change to smaller font size from \normalsize
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}%
\endgroup
\caption{This is a table caption.}
\end{table}
\end{document}
再次,这里可能需要限定范围来限制字体的变化。
graphicx
或\scalebox{<factor>}
是\resizebox{<width>}{<height>}
一个选项。您可以指定适合高度的<height>
长度或部分。<width>
的!
可确保在调整大小期间保持纵横比:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}%
\hspace{2em}%
\resizebox{!}{.8\height}{%
\begin{tabular}{ c c }
1&This \\
\hline
2&is \\ 3&a \\ 4&\texttt{tabular} \\ 5&with \\ 6&twelve \\
7&rows \\ 8&that \\ 9&is \\ 10&just \\ 11&too \\ 12&tall.
\end{tabular}}
\caption{This is a table caption.}
\end{table}
\end{document}
- 如果你的
tabular
页面太高,你可以考虑跨页面边界手动(即设置单独的tabular
s 以适应每页)。这可能需要使用单独的浮动(也许继续字幕)然而,有些软件包可以帮助实现这样的自动化打破:longtable
,supertabular
,ltxtable
,xltabular
和xtab
有几个这样的包。CTAN 上列出了更多软件包.另请参阅如何制作一个占用多页空间的表格?或者使表格跨越多页。
以下示例直接取自文档longtable
,说明了环境组件的构造longtable
,以便将表格分成多页(带有“连续标题”):
\documentclass{article}
\usepackage{longtable}
\def\v{\char`}
\begin{document}
% Note: Various parts of the following table will
% *not* line up correctly until this document has been run
% through LaTeX several times. This is a characteristic feature of
% this package, as described below.
\begin{longtable}{@{*}r||p{1in}@{*}}
KILLED & LINE!!!! \kill
\caption
[An optional table caption (used in the list of tables)]
{A long table\label{long}} \\
\hline\hline
\multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of the table} \\
\textsc{First} & \textsc{Second} \\
\hline\hline
\endfirsthead
\caption[]{(continued)} \\
\hline\hline
\multicolumn{2}{@{*}c@{*}}%
{This part appears at the top of every other page} \\
\textbf{First} & \textbf{Second} \\
\hline\hline
\endhead
\hline
This goes at the & bottom. \\
\hline
\endfoot
\hline
These lines will & appear \\
in place of the & usual foot \\
at the end & of the table \\
\hline
\endlastfoot
\texttt{longtable} columns are specified & in the \\
same way as in the \texttt{tabular} & environment. \\
``\verb~@{*}r||p{1in}@{*}~'' & in this case. \\
Each row ends with a & ``\verb|\\|'' command. \\
The ``\verb|\\|'' command has an & optional \\
argument, just as in & the \\
\texttt{tabular} & environment. \\[10pt]
See the effect of ``\verb|\\[10pt]|'' & ? \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Also ``\verb|\hline|'' may be used, & as in \texttt{tabular}. \\
\hline
That was a ``\verb|\hline|'' & . \\
\hline\hline
That was ``\verb|\hline\hline|'' & . \\
\multicolumn{2}{||c||}%
{This is a \ttfamily\v\\multicolumn\v{2\v}\v{||c||\v}} \\
If a page break occurs at a ``\verb|\hline|'' then & a line is drawn \\
at the bottom of one page and at the & top of the next. \\
\hline
The ``\verb|[t] [b] [c]|'' argument of \texttt{tabular} & can not be used. \\
The optional argument may be one of & ``\verb|[l] [r] [c]|'' \\
to specify whether the table should be & adjusted \\
to the left, right & or centrally. \\
\hline\hline
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Some lines may take up a lot of space, like this: &
\raggedleft This last column is a ``\texttt{p}'' column so this
``row'' of the table can take up several lines. Note however that
\TeX\ will never break a page within such a row. Page breaks only
occur between rows of the table or at ``\verb|\hline|'' commands.
\tabularnewline
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
Lots of lines & like this. \\
\hline
Lots\footnote{This is a footnote.} of lines & like this. \\
Lots of lines & like this\footnote{\texttt{longtable} takes special
precautions, so that footnotes may also be used in `\texttt{p}' columns.} \\
\hline
Lots of lines & like this. \\
Lots of lines & like this.
\end{longtable}
\end{document}
3. 我的tabular
太宽了和对于我放置的位置来说太高了。我该怎么办?
通常,可以结合上述方法来改善宽度/高度。可能存在一些不兼容的选择(例如,调整 的大小longtable
)。
答案2
如果文档由纵向格式的页面组成,并且表格在横向格式下可以适合纸张宽度,则可以考虑制作一个跨越多页的旋转 90 度的长表。
(人们可能仅当表仅用于枯燥的查找时才会这样做,例如价格表或类似表,在这种情况下,通过一次查看多条记录来了解数据组之间的相关性并不重要。)
现在您可以使用 zref 和 LaTeX2e 内核中最近引入的钩子系统:
对于长表,临时更改布局,以便交换页面宽度和页面高度。
在 longtable 中,使用 zref 包的工具在第一个和最后一个单元格中设置一个标签,以保存有关 longtable 开始和结束的绝对页码的信息。
\ShipoutBox
如果绝对页码在 longtable 环境开头和结尾处放置的 zref 标签所表示的页面范围内,则使用新的挂钩系统向每次发货前执行的挂钩添加将页面旋转 90 度的指令。
\documentclass{article}
\usepackage{graphicx}
\usepackage[abspage]{zref}
\usepackage{longtable}
\usepackage{blindtext}
\makeatletter
% A scratch loop for repeating #3 while counting from #1 to #2.
% As counter is used \scratchmacro
% #3 is expanded until finding an unexpandable token.
% If the unexpandable token is a space token it is discarded.
\newcommand\scratchmacro{}
\newtoks\scratchtoks
\newcommand\PassFirstToSecond[2]{#2{#1}}
\newcommand\scratchtoksloop[3]{%
\begingroup
\def\scratchmacro{#1}%
\scratchtoks{\endgroup}%
\loop
\scratchtoks\expandafter{\the\expandafter\scratchtoks\romannumeral`\^^@#3}%
\ifnum\scratchmacro < #2 %
\edef\scratchmacro{\the\numexpr\scratchmacro+1\relax}%
\repeat
\the\scratchtoks
}%
% This checks if the current value of the abspage-counter is within the
% range given by zref-label #1 and zref-label #2.
\newcommand\saveabspage[1]{\zref@labelbyprops{#1}{abspage}}%
\newcommand\CheckWhetherAbsPageInLabelrange[2]{%
\zref@ifrefundefined{#1}{\@secondoftwo}{%
\zref@ifrefundefined{#2}{\@secondoftwo}{%
\zref@ifrefcontainsprop{#1}{abspage}{%
\zref@ifrefcontainsprop{#2}{abspage}{%
\ifnum\zref@extractdefault{#1}{abspage}{-1}>\value{abspage}%
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\@secondoftwo}{%
\ifnum\zref@extractdefault{#2}{abspage}{-1}<\value{abspage}%
\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\@secondoftwo}{\@firstoftwo}%
}%
}{\@secondoftwo}%
}{\@secondoftwo}%
}%
}%
}%
\makeatother
% The zref-label at the start of the longtable is "tablesfirstpage".
% The zref-label at the end of the longtable is "tableslastpage".
% Add to the hook carried out at every shipout the directive to check if
% absolute page is in range denoted by these labels, and if so,
% to rotate the page/to rotate \ShipoutBox:
\AddToHook{shipout/before}{%
\CheckWhetherAbsPageInLabelrange{tablesfirstpage}{tableslastpage}{%
\setbox\ShipoutBox=\vbox{\hbox{\rotatebox[origin=c]{90}{%
\vbox{\hbox{\box\ShipoutBox\kern\ifodd\value{page}\evensidemargin\else\oddsidemargin\fi}}%
}}}%
}{%
}%
}%
% Just make sure...
\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%
\begin{document}
\blindtext
\newpage
\begingroup
\ifodd\value{abspage}\newpage\else\newpage\null\newpage\fi
% ---- Layout ----------------------------------------------------------------------
% For typesetting the longtable temporarily change the layout so that
% width and height of page are exchanged and textwidth is increased etc:
\pagestyle{plain}%
\csname zref@ifrefundefined\endcsname{tablesfirstpage}{%
\paperwidth=\the\expandafter\paperheight
\expandafter\paperheight\expandafter=\the\paperwidth
\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%
\textwidth=\paperwidth
}{%
\textwidth=\paperheight
}%
\advance\textwidth-3cm\relax
\evensidemargin=\dimexpr-1in+1.5cm\relax
\oddsidemargin=\dimexpr-1in+1.5cm\relax
\marginparsep=2mm\relax
\marginparwidth=\dimexpr2cm-2\marginparsep\relax
\csname zref@ifrefundefined\endcsname{tablesfirstpage}{%
\textheight=\paperheight
}{%
\textheight=\paperwidth
}%
\advance\textheight-3cm\relax
\topmargin=\dimexpr-1in+1.5cm\relax
\headheight=0pt\relax
\headsep=0pt\relax
{\normalfont
\setbox\csname @tempboxa\endcsname\hbox{0123456789}%
\footskip=\dimexpr 1cm -.5\dp\csname @tempboxa\endcsname
+.5\ht\csname @tempboxa\endcsname\relax
\expandafter}\expandafter\footskip\expandafter=\the\footskip
\csname @colht\endcsname=\textheight
\csname @colroom\endcsname=\textheight
\vsize=\textheight
\columnwidth=\textwidth
\hsize=\columnwidth
\linewidth=\hsize
\parindent=0pt\relax
% ---- Layout-changes done. --------------------------------------------------------
\begin{longtable}{|c|c|c|c|}
\caption{Caption of Longtable}\label{LongtableLabel}\\
\hline
\saveabspage{tablesfirstpage}number&left&middle&right\\
\hline\endfirsthead
\hline
number&left&middle&right\\
\hline\endhead
\hline
\multicolumn{4}{|c|}{This is a clever remark.}\\
\hline\endfoot
\hline
\multicolumn{4}{|c|}{This is a clever remark.\saveabspage{tableslastpage}}\\
\hline\endlastfoot
\scratchtoksloop{1}%
{100}%
{%
\expandafter\hbox\expandafter{%
\expandafter\PassFirstToSecond
\expandafter{\scratchmacro}{\hphantom{100}\llap}%
}%
&left&middle&\scratchtoksloop{1}{11}{ this is wide }\\%
}%
\end{longtable}%
\newpage
\endgroup
% ---- After typesettig the longtable reset the page layout ------------------------
\csname @colht\endcsname=\textheight
\csname @colroom\endcsname=\textheight
\vsize=\textheight
\columnwidth=\textwidth
\hsize=\columnwidth
\linewidth=\hsize
\blindtext
\end{document}