Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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}
share|improve this answer
    
Thank you @Jake, I'm still wrapping my head around combining packages. So much to learn. –  Forkrul Assail Dec 5 '12 at 15:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.