我有一张包含数百行的大表。我想在表的每一页上重复前两行。如何在 TeX 中实现?
答案1
这俩 longtable
包和supertabular
包可以做到这一点。下面是使用的示例longtable
:
\documentclass{article}
\usepackage{longtable}
\begin{document}
\begin{longtable}{ccc}
\hline
Column 1 & Column 2 & Column 3\\
\hline
\endhead % all the lines above this will be repeated on every page
A & B & C\\
A & B & C\\
... many lines of table ...
\end{longtable}
\end{document}
基本思想相同,supertabular
但跨页面设置重复元素的命令已经完成前环境supertabular
本身:
\documentclass{article}
\usepackage{supertabular}
\begin{document}
\tablehead{%
\hline
Column 1 & Column 2 & Column 3\\
\hline}
\tabletail{\hline}
\begin{supertabular}{ccc}
A & B & C\\
A & B & C\\
\end{supertabular}
\end{document}
答案2
带有连续页眉和页脚的解决方案
\documentclass{article}
\usepackage{longtable}
\begin{document}
\begin{longtable}{ccc}
\caption{My caption for this table\label{foo}}\\\hline
Column 1 & Column 2 & Column 3\\\hline
\endfirsthead
\multicolumn{3}{@{}l}{\ldots continued}\\\hline
Column 1 & Column 2 & Column 3\\\hline
\endhead % all the lines above this will be repeated on every page
\hline
\multicolumn{3}{r@{}}{continued \ldots}\\
\endfoot
\hline
\endlastfoot
A & B & C\\ A & B & C\\
A & B & C\\ A & B & C\\
A & B & C\\ \newpage
A & B & C\\ A & B & C\\
A & B & C\\ A & B & C\\
\end{longtable}
\end{document}
答案3
tblr
环境的替代解决方案tabularray
包裹:
\documentclass{article}
\usepackage[a6paper,margin=1.5cm]{geometry}
\usepackage{tabularray}
\begin{document}
\begin{longtblr}[
caption = {Long Title},
label = {tblr:test},
]{
colspec = {lll},
hlines,
rowhead = 2,
}
Column 1 & Column 2 & Column 3 \\
Column 1 & Column 2 & Column 3 \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
Alpha & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kapp & Lambdaa \\
\end{longtblr}
\end{document}
答案4
也许该软件包tabularray
可以用更简单的方式解决这个问题。就像(下面的代码不知何故从用户 Alan Munn 编写的代码中复制而来):
\documentclass{article}
\usepackage{tabularray} % A newest package for tables written in LaTeX 3
\begin{document}
\begin{longtblr}{
colspec = {ccc},
rowhead = 1 % indidate the program to repeat the 1st row in the beginning of every page.
}
\hline
Column 1 & Column 2 & Column 3\\
\hline
A & B & C\\
A & B & C\\
%... many lines of table ...%
\end{longtblr}
\end{document}
至于页眉,也可以在开始代码块中设置\begin{longtblr}{...}
,更详细的信息可以阅读相应的PDF文件。
然而,有一个副作用,由于包使用的机制,渲染所需的时间可能会更长。