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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

  1. a caption above it and
  2. its 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 MWE, where data.csv is a 2 column csv file with enough data to fill multiple pages:



    begin table=\begin{longtable},
    every head row/.style={before row={%
    \caption{This is a Table with Data}%
    }, 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}

share|improve this question
up vote 13 down vote accepted

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.


\usepackage[a4paper,top=4in,bottom=4in,right=1in,left=1in]{geometry} %%% change the margins in your file suitably.


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

    empty header,
    begin table=\begin{longtable},
    every first row/.append style={before row={%
    \caption{This is a Table with Data}%
    \textbf{column 1} &\textbf{column 2} \\ \toprule    
    {{\bfseries Table \thetable\ Continued from previous page}} \\
    \textbf{column 1} &\textbf{column 2} \\ \toprule  
    \midrule \multicolumn{2}{r}{{Continued on next page}} \\ \bottomrule
    \multicolumn{2}{r}{{Concluded}} \\ \bottomrule
    end table=\end{longtable},
    col sep=comma,
    string type,


enter image description here

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

share|improve this answer

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

I'd just input the csv file into a longtable

enter image description here




\catcode`\,=4 %
\caption{a table of data}
\textbf{Column 1}&\textbf{Column 2}\endfirsthead%
\textbf{Column 1}&\textbf{Column 2}\endhead%
\@@input data.csv %

share|improve this answer

EDIT: This will produce the result that you want. The only caveat being that the second row in the file sometable.dat has to be manually entered, which forces the string type style of all the columns.


temperature value
Temperature(\si{\kelvin}) Value(\si{m^3})
15.00 1.000342E+00
16.00 1.000038E+00
18.00 9.991696E-01
20.00 9.976573E-02
22.00 9.954760E-02
24.00 9.926016E-02
25.00 9.908970E-02
26.00 9.890101E-02
27.00 9.869378E-03
28.00 9.846772E-03
29.00 9.822252E-03
30.00 9.793544E-03
31.00 9.757798E-04
32.00 9.714558E-04
33.00 9.663367E-04
34.00 9.603773E-04
35.00 9.535319E-04
36.00 9.457552E-04
37.00 9.370016E-04
38.00 9.272257E-05
39.00 9.164286E-05
40.00 9.053571E-05
42.00 8.832143E-05
44.00 8.610714E-05
45.00 8.500000E-05
46.00 8.389286E-05
48.00 8.167857E-05
50.00 7.946429E-05
55.00 7.392857E-05
60.00 6.839286E-05
65.00 6.285714E-02
70.00 5.730197E-02
75.00 5.095251E-02
80.00 4.558582E-02
85.00 4.192582E-02
90.00 3.825244E-02
95.00 3.396510E-02
98.15 3.151784E-02
100.00 3.035714E-02
103.15 2.861339E-02
113.15 2.307768E-02
123.15 1.767093E-02
125.00 1.680902E-02
138.15 1.222368E-02
150.00 8.928571E-03
153.15 8.056696E-04
173.15 4.209043E-03
175.00 3.996861E-04
198.15 1.887255E-04
200.00 1.785714E-04
223.15 6.901849E-04
225.00 5.786391E-04
        begin table=\begin{longtable},
        end table=\end{longtable},
            string type,
            column name=Temperature(K)
            string type,
            column name=Value($m^3$)
        every head row/.append style={before row={\caption{Some caption}\label{tab:sometable}\\\toprule},after row=\midrule\endfirsthead},
        every first row/.append style={before row={\multicolumn{2}{c}{}\\ \caption[]{Some caption}\\\toprule},after row=\midrule\endhead},
        every last row/.style={after row=\bottomrule},

    Refer to the table here \ref{tab:sometable}.

Page 1 Page 2

share|improve this answer

Your Answer


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.