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{
empty header/.style={
every head row/.style={output empty row},
}
}
}{
% versions up to and including 1.5.1 need this:
\pgfplotstableset{
empty header/.style={
typeset cell/.append code={%
\ifnum\pgfplotstablerow=-1 %
\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
\fi
}
}
}
}
%%%-----------------------------------------------
\pgfplotstabletypeset[
empty header,
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
\endfirsthead
%
\multicolumn{2}{c}%
{{\bfseries Table \thetable\ Continued from previous page}} \\
\toprule
%
\textbf{column 1} &\textbf{column 2} \\ \toprule
\endhead
%
\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.
If you put the caption in the main table body longtable
just considers it a normal row of the table and so doesn't consider it wrong to have that row as the only thing on the last page.
It is better to put it into the head or foot section so \endlastfoot
if you want it last. If necessary you can also put a line or two of the actual table data into the last foot if you want to ensure that some lines stay with the caption.
So
\begin{longtable}{@{}rr@{${},{}$}rr@{${},{}$}rrr@{}}
\bottomrule
\caption{Sűrűségmérő egyenesek - Vízszintes}
\endlastfoot
\toprule
...
\end{longtable}
Not
\begin{longtable}{@{}rr@{${},{}$}rr@{${},{}$}rrr@{}}
\toprule
...
\bottomrule
\caption{Sűrűségmérő egyenesek - Vízszintes}
\end{longtable}
Best Answer
This is given as a model for getting you started.