# pdfplotstable longtable with caption and repeating header

I would like to use the pgfplotstable package in order to import data from a .csv file into a multi-page table. I would like for the table to have a caption above it and I would like for the table header to repeat at the top of every page. It seems that I'm only able to have one or the other. I can import a table and have a caption or I can import a table and have the header repeat on every page. I can't get both to work at the same time. Here is my minimal example, where data.csv is a 2 column csv file with enough data to fill multiple pages:

\documentclass{minimal}

\usepackage{pgfplotstable}
\usepackage{longtable}
\begin{document}

\pgfplotstabletypeset[
begin table=\begin{longtable},
\caption{This is a Table with Data}%
\label{tab:DataTable}
\hline
}, after row=\hline},
every nth row={1}{before row=\hline},
every last row/.style={before row=\hline, after row=\hline},
col sep=comma,
string type,
columns/A/.style={column name=\textbf{Column 1}, column type={|c}},
columns/B/.style={column name=\textbf{Column 2}, column type={|c}},
end table=\end{longtable}
]{data.csv}

\end{document}

-

For some reasons, if you want to keep using pgfplotstable, this is the solution. Otherwise you may adopt @David's answer above. I have given some dummy data in the file.

\documentclass{article}

\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}
\begin{filecontents}{data.csv}
column1,column2
5001,102
5002,75
5003,115
5004,45
5005,97
5036,110
5037,77
5038,147
5039,89
5040,62
5041,160
5042,102
5043,56
5044,86
5100,74
5101,65
5102,131
5103,90
5104,99
\end{filecontents}%

\begin{document}

%%% Code from Dr. Christian ------ for not using headers.----------------------
\pgfkeysifdefined{/pgfplots/table/output empty row/.@cmd}{
% upcoming releases offer this more convenient option:
\pgfplotstableset{
}
}
}{
% versions up to and including 1.5.1 need this:
\pgfplotstableset{
typeset cell/.append code={%
\ifnum\pgfplotstablerow=-1 %
\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
\fi
}
}
}
}
%%%-----------------------------------------------

\pgfplotstabletypeset[
begin table=\begin{longtable},
every first row/.append style={before row={%
\caption{This is a Table with Data}%
\label{tab:DataTable}\\\toprule
\textbf{column 1} &\textbf{column 2} \\ \toprule
%
\multicolumn{2}{c}%
{{\bfseries Table \thetable\ Continued from previous page}} \\
\toprule
%
\textbf{column 1} &\textbf{column 2} \\ \toprule
%
\midrule \multicolumn{2}{r}{{Continued on next page}} \\ \bottomrule
\endfoot
%
\midrule
\multicolumn{2}{r}{{Concluded}} \\ \bottomrule
\endlastfoot
}},%
%
end table=\end{longtable},
col sep=comma,
string type,
]{data.csv}

\end{document}


I used booktabs for lines and avoided putting a line after each row as it improves readability.

-

I think the package is making it seem more complicated than it need be.

I'd just input the csv file into a longtable

1,2
3,4
5,6
7,8
9,10
11,12


\documentclass{article}

\textheight5\baselineskip
\usepackage{longtable}
\begin{document}

\begingroup
\obeylines%
\catcode\,=4 %
\def^^M{\\}%
\makeatletter%
\begin{longtable}{rr}%
\caption{a table of data}
`