![使用 pgfplotstable 导入文件并将表格拆分到多个页面](https://linux22.com/image/244435/%E4%BD%BF%E7%94%A8%20pgfplotstable%20%E5%AF%BC%E5%85%A5%E6%96%87%E4%BB%B6%E5%B9%B6%E5%B0%86%E8%A1%A8%E6%A0%BC%E6%8B%86%E5%88%86%E5%88%B0%E5%A4%9A%E4%B8%AA%E9%A1%B5%E9%9D%A2.png)
我用来pgfplotstable
导入包含多行多列的文件,以便创建自定义表格。有些表格很长,覆盖很多页。有没有办法自动分配每页显示的行数?我在文档中找不到任何内容。
我的第一次尝试是使用 MWE,它只是重复每个所需页面的代码。一定有更好、更有效的方法。也许存在 Do While 或 For... 语法?
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{filecontents}
\begin{document}
\begin{filecontents}{testdata.dat}
Idx Nam Dim Grd
1 Ady 53 F
2 Bar 72 C
3 Cor 83 B
4 Dar 58 D
5 Esa 68 C
6 Foo 67 C
7 Gar 74 C
8 Hur 65 D
9 Jaz 85 B
10 Ker 91 A
\end{filecontents}
{\large Table 1}
\pgfplotstabletypeset[col sep=space,
header=true,
columns={Idx,Nam,Dim,Grd}, % display specified columns
columns/Idx/.style={fixed,fixed zerofill,precision=0,column type=r},
columns/Nam/.style={column type=l,string type},
columns/Dim/.style={fixed,fixed zerofill,precision=1,column type=r},
columns/Grd/.style={column type=l,string type},
skip rows between index={5}{83}, % {43}{83}
% requires booktabs to place horiz rules
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule}
]{testdata.dat}
\newpage
{\large Table 1 (cont.)}
\pgfplotstabletypeset[col sep=space,
header=true,
columns={Idx,Nam,Dim,Grd}, % display specified columns
columns/Idx/.style={fixed,fixed zerofill,precision=0,column type=r},
columns/Nam/.style={column type=l,string type},
columns/Dim/.style={fixed,fixed zerofill,precision=1,column type=r},
columns/Grd/.style={column type=l,string type},
skip rows between index={0}{5}, % {0}{43}
% skip rows between index={10}{83},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule}
]{testdata.dat}
\end{document}
答案1
您可以通过设置来使用longtable
包pgfplotstable
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
要重复标题行,请使用every head row/.style={before row=\toprule, after row=\midrule\endhead}
(\endhead
表示longtable
这是应在每个表格部分顶部重复的部分的结尾)。
\documentclass[a5paper]{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{filecontents}
\usepackage{longtable}
\begin{document}
\begin{filecontents}{testdata.dat}
Idx Nam Dim Grd
1 Ady 53 F
2 Bar 72 C
3 Cor 83 B
4 Dar 58 D
5 Esa 68 C
6 Foo 67 C
7 Gar 74 C
8 Hur 65 D
9 Jaz 85 B
10 Ker 91 A
1 Ady 53 F
2 Bar 72 C
3 Cor 83 B
4 Dar 58 D
5 Esa 68 C
6 Foo 67 C
7 Gar 74 C
8 Hur 65 D
9 Jaz 85 B
10 Ker 91 A
1 Ady 53 F
2 Bar 72 C
3 Cor 83 B
4 Dar 58 D
5 Esa 68 C
6 Foo 67 C
7 Gar 74 C
8 Hur 65 D
9 Jaz 85 B
10 Ker 91 A
\end{filecontents}
{\large Table 1}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\pgfplotstabletypeset[col sep=space,
header=true,
columns={Idx,Nam,Dim,Grd}, % display specified columns
columns/Idx/.style={fixed,fixed zerofill,precision=0,column type=r},
columns/Nam/.style={column type=l,string type},
columns/Dim/.style={fixed,fixed zerofill,precision=1,column type=r},
columns/Grd/.style={column type=l,string type},
% requires booktabs to place horiz rules
every head row/.style={before row=\toprule, after row=\midrule\endhead},
every last row/.style={after row=\bottomrule}
]{testdata.dat}
\end{document}