使用 pgfplotstable 导入文件并将表格拆分到多个页面

使用 pgfplotstable 导入文件并将表格拆分到多个页面

我用来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

您可以通过设置来使用longtablepgfplotstable

\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}

相关内容