“longtable”文档说使用
\caption{Your caption here}
用于标题,但是在 pgfplotstabletypeset 和 longtable 一起使用的示例中,我看不到在哪里指定“longtable”选项。
MWE:您会看到,目前表 1 的文本仅包含在内,但这意味着它将被排除在目录和表格索引之外。
\documentclass{article}
% MWE from http://tex.stackexchange.com/questions/40411/import-files-with-pgfplotstable-and-split-tables-across-multiple-pages
\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage[a4paper,top=4in,bottom=4in,right=1in,left=1in]{geometry} %%% change the margins in your file suitably.
\usepackage{filecontents}
\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
\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}
我应该把它放在\pgfplotstableset
或\pgfplotstabletypeset
部分吗?使用什么语法?
答案1
在 中longtable
,\caption
命令需要进入表中自己的行。在您的示例中,您可以输入\caption\\
以下before row
键:
\documentclass{article}
% MWE from http://tex.stackexchange.com/questions/40411/import-files-with-pgfplotstable-and-split-tables-across-multiple-pages
\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage[a4paper,top=4in,bottom=4in,right=1in,left=1in]{geometry} %%% change the margins in your file suitably.
\usepackage{filecontents}
\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
\end{filecontents}
\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=\caption{Some numbers}\\\toprule, after row=\midrule\endhead},
every last row/.style={after row=\bottomrule}
]{testdata.dat}
\end{document}