5

The 'longtable' documentation says to use

\caption{Your caption here}

for captions, but I can't see where to specify the 'longtable' options in the example where pgfplotstabletypeset and longtable is used together.

MWE: You'll see currently the Table 1 text is just included, but that would mean it would be excluded from ToC and index of tables.

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

Would I put it in the \pgfplotstableset or \pgfplotstabletypeset sections, and with what syntax?

1 Answers1

7

In a longtable, the \caption command needs to go into its own line in the table. In your example, you could put \caption\\ into the before row key:

\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}
Jake
  • 232,450
  • Thank you @Jake, I'm still wrapping my head around combining packages. So much to learn. – Forkrul Assail Dec 05 '12 at 15:44
  • It's also possible to combine \caption with \endfirsthead, in case the longtable spans multiple pages. See chapter 2.5 Customizing and Getting the Tabular Code in Manual for Package PgfplotsTable. – Joel Purra Sep 11 '14 at 12:58
  • This works great with one addition and one remark. I had to put two \\ between \caption and \toprule. Otherwise the heading would not reach completely from left to right. What should be mentioned is that the caption will be repeated on every page for a multi page document when this approach is used. – MKroehnert Jan 28 '15 at 11:01