# Avoid multiple entries of caption in list of tables using pgfplotstable with longtable

I'm using pgfplotstable to display data from .csv files and it happens that displayed tables break over three pages. The problem is, that for every page an entry is placed into the list of tables. Here the way I currently use pgfplotstable:

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

\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{filecontents}
\usepackage{longtable}

\begin{document}
\listoftables
\begin{filecontents}{testdata.dat}
Idx  Nam Dim Grd
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
2   Bar 72  C
3   Cor 83  B
\end{filecontents}

\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}

\pgfplotstabletypeset[ col sep=space
, every head row/.style={ before row=\caption{ The Caption }\\\toprule
, every last row/.style={after row=\bottomrule}
] {testdata.dat}

\end{document}


Is there a way keeping repetition of caption and head per page, but only placing one entry in list of tables?

Best regards!

• for longtable you want \caption in the \endfirsthead and \caption[] in \endhead I'm not sure anout the pgfplotstable key names to acjhieve that – David Carlisle Sep 12 '14 at 15:39
• Currently I'm experimenting with addcontentsline{lot}{section}{The Caption} und using \caption*{} instead of \caption{} in \pgfplotstabletypeset[…]. It reduces the appearance in the list of tables to one, but the number of the table is missing. Any ideas to retrieve the number? – user3389669 Sep 16 '14 at 8:00

First of all: The following post is only a workaround and no acceptable answer. I would be pleased if there is someone who can post the true answer.

Anyway, after hours of experimenting with @David Carlisle hints and examples of the manual of pgfplotstable, I'm using this right now:

\documentclass{report} % Note that I'm using report (chapters are now available)

\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{filecontents}

\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{filecontents}
\usepackage{longtable}

\begin{document}

\listoftables

\begin{filecontents}{testdata.dat}
Idx  Nam Dim Grd
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
2   Bar 72  C
3   Cor 83  B
\end{filecontents}

\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}

\chapter{ Stuff with tables }
\newcounter{tablecounter}

\stepcounter{tablecounter}
% Place a line starting with Number of chapter followed by a dot, followed by the
% number of the counter, followed by free space and then followed by the entry.
\pgfplotstabletypeset[ col sep=space
, every head row/.style={ before row=\caption*{ The Caption 1 }\\\toprule % Note that I'm using \caption*{} instead of \caption{}
, every last row/.style={after row=\bottomrule}
] {testdata.dat}

\stepcounter{tablecounter}
\pgfplotstabletypeset[ col sep=space
, every head row/.style={ before row=\caption*{ The Caption 2 }\\\toprule
, every last row/.style={after row=\bottomrule}
] {testdata.dat}

\end{document}


The workaround achieves the following:

1. Have a caption above the table and repeat it, if the table breaks over several pages
2. Have a header above the table and repeat it, if the table breaks over several pages
3. Place only one entry in the list of tables (lot) having the shape: .

Off topic: This post helped me finding this workaround.

I find another workaround. For longtable, you can write like

\caption{The Caption}
Column 1 & Column 2
\caption[]{The Continued Caption}
Column 1 & Column 2


For pgfplotstable, you can duplicate the head line in the data, and add two different captions to the 1st and 2nd row, using every head row and every first row.

Here's the code. I make the table longer to expand to 2 pages.

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

\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{filecontents}
\usepackage{longtable}

\begin{document}
\listoftables
\begin{filecontents}{testdata.dat}
Idx  Nam Dim Grd
Idx  Nam Dim Grd %%% Duplicate here
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
2   Bar 72  C
3   Cor 83  B
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
2   Bar 72  C
3   Cor 83  B
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
2   Bar 72  C
3   Cor 83  B
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
2   Bar 72  C
3   Cor 83  B
\end{filecontents}

\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}

\pgfplotstabletypeset[ col sep=space
, string type %%% Add this line