我在想将长表包含到我的博士论文中时遇到了问题。这似乎是一个常见问题(例如),但我对 Latex 还不熟悉,我找到的解决方案对我没有用。问题很简单,longtable 不适合页面和列的宽度。这是一个 MWE:
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{booktabs}
\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\setlength\LTcapwidth{\linewidth}
\setlength\LTleft{\fill}
\setlength\LTright{\fill}
\begin{longtable}{@{\extracolsep{\fill}}lll@{}}\toprule
\textbf{Date} & \textbf{Example - Example and Example} & \textbf{Example - Example and Example} \\* \midrule
\endhead
%
\bottomrule
\endfoot
%
\endlastfoot
%
1460 & Long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text. & \\
1470 & Long text long text long text long text long text long text long text long text long text long text. & \\
1470-1535 & & Long text long text long text long text long text long text long text long text long text long text long text. \\
1532 & Long text long text long text long text long text long text long text long text long text. & \\
1535-36 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \\
1537 & Long text long text long text long text long text long text long text long text long text long text long text long text long text. & \\
1538 & Long text long text long text long text long text long text long text long text long text long text long text. & \\
1541 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \\
[...]
2021 & & Long text long text long text long text long text long text long text long text. \\* \bottomrule
\end{longtable}
感谢您的帮助。
答案1
第二列和第三列单元格中的文本比文本宽度长,因此这些列中的单元格必须允许文本分成多行。此类功能具有p{width}
列类型,但更简单的是使用X
在包中定义的列类型xltabular
(结合tabularx
和longtable
,在包等longtblr
中定义)。tabularray
使用longtblr
MWE 您的表格可以如下:
\documentclass{report}
\usepackage[margin=2.5cm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{lipsum}
\begin{document}
\begingroup
\NewTblrTheme{fancy}{
\SetTblrStyle{head}{font=\small}
\SetTblrStyle{foot}{font=\footnotesize\itshape}
\SetTblrStyle{caption-tag}{font=\bfseries}
}
\begin{longtblr}[
theme = fancy,
caption = {Long table \texttt{longtblr}},
label = {tab:longtblr}]{
rowhead = 1,
colspec = {@{} l X[j] X[j] @{}},
row{1} = {font=\bfseries}
}
\toprule
Date & Example - Example and Example
& Example - Example and Example \\*
\midrule
% table body
1460 & \lipsum[1]
& \\
1461 & & \lipsum[2] \\
1470 & \lipsum[3].
& \\
1470-1535 & & Long text long text long text long text long text long text long text long text long text long text long text. \\
1532 & Long text long text long text long text long text long text long text long text long text.
& \\
1535-36 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \\
1537 & Long text long text long text long text long text long text long text long text long text long text long text long text long text.
& \\
1538 & Long text long text long text long text long text long text long text long text long text long text long text.
& \\
1541 & & Long text long text long text long text long text long text long text long text long text long text long text long text long text. \\
[...] & & \\
2021 & & Long text long text long text long text long text long text long text long text. \\*
\bottomrule
\end{longtblr}
\endgroup
\end{document}