0

Consider the following MWE which uses pgfplotstable and longtable to output some csv file content. The table counter are incrementet twice for each table added. Why?

\begin{filecontents*}{mytable.csv}
Chem.;Avg. Conc.;Avg. Conc. Norm.; Conc. Unit;Mass sum;Mass unit
ammonium;159083,33;114450,21;\si{\micro\gram\per\liter};2839,463;\si{\kilo\gram}
\end{filecontents*}


\documentclass{article}

\usepackage{booktabs, longtable, geometry} 
\usepackage{siunitx}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest,}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
%every head row/.append style={before row=\captionof{table{Caption}}
}
\usepackage{capt-of}

\begin{document}

{\centering
\captionof{table}{First table}
\pgfplotstabletypeset[
    header=has colnames,
    col sep=semicolon,
    read comma as period=true,
    display columns/0/.style={column type={l},string type}, 
    display columns/1/.style={sci,sci zerofill,sci sep align,},
    display columns/2/.style={sci,sci zerofill,sci sep align,},
    display columns/3/.style={column type={l},string type}, 
    display columns/4/.style={sci,sci zerofill,sci sep align,},
    display columns/5/.style={column type={l},string type}, 
]{mytable.csv}\par
}

{\centering
\captionof{table}{Second table}
\pgfplotstabletypeset[
    header=has colnames,
    col sep=semicolon,
    read comma as period=true,
    display columns/0/.style={column type={l},string type}, 
    display columns/1/.style={sci,sci zerofill,sci sep align,},
    display columns/2/.style={sci,sci zerofill,sci sep align,},
    display columns/3/.style={column type={l},string type}, 
    display columns/4/.style={sci,sci zerofill,sci sep align,},
    display columns/5/.style={column type={l},string type}, 
]{mytable.csv}\par
}

{\centering
\captionof{table}{Third table}
\pgfplotstabletypeset[
    header=has colnames,
    col sep=semicolon,
    read comma as period=true,
    display columns/0/.style={column type={l},string type}, 
    display columns/1/.style={sci,sci zerofill,sci sep align,},
    display columns/2/.style={sci,sci zerofill,sci sep align,},
    display columns/3/.style={column type={l},string type}, 
    display columns/4/.style={sci,sci zerofill,sci sep align,},
    display columns/5/.style={column type={l},string type}, 
]{mytable.csv}\par
}

\end{document}

enter image description here

Holene
  • 6,920

2 Answers2

1

You have used longtable inside table , which does no good as table is a box so can not split so then a table \caption and longtable both increment the table caption.

Either just use longtable, and use \caption inside longtable or use \caption inside table and use tabular.

David Carlisle
  • 757,742
  • Didn't consider table being a box, I just added table to show that it happens there as well. Please see my edit. This happens also without the table environment, replacing caption with the captionof macro. Am I positioning the caption(of) wrong? – Holene Jan 28 '16 at 08:36
  • 1
    @Holene same issue with \captionof that increments the counter too, but in longtable, longtable itself increments the counter and \caption does not (so you can \caption repeated for headings, etc) so if you are using longtable you need to use its caption (or just set the counter back by one). – David Carlisle Jan 28 '16 at 08:49
0

This question already (kind of) has been answered: Caption with longtable and pgfplotstabletypeset

The problem is the positioning of the caption, which must be added as

every head row/.style={before row=\caption{First table}\tabularnewline}

in the optional argument of \pgfplotstabletypset macro. captionof does not work (and is not needed).

\begin{filecontents*}{mytable.csv}
Chem.;Avg. Conc.;Avg. Conc. Norm.; Conc. Unit;Mass sum;Mass unit
ammonium;159083,33;114450,21;\si{\micro\gram\per\liter};2839,463;\si{\kilo\gram}
\end{filecontents*}


\documentclass{article}

\usepackage{booktabs, longtable, geometry} 
\usepackage{siunitx}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest,}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\usepackage{capt-of}

\begin{document}

{\centering
%\captionof{table}{First table}
\pgfplotstabletypeset[
    header=has colnames,
    col sep=semicolon,
    read comma as period=true,
    display columns/0/.style={column type={l},string type}, 
    display columns/1/.style={sci,sci zerofill,sci sep align,},
    display columns/2/.style={sci,sci zerofill,sci sep align,},
    display columns/3/.style={column type={l},string type}, 
    display columns/4/.style={sci,sci zerofill,sci sep align,},
    display columns/5/.style={column type={l},string type}, 
    every head row/.style={before row=\caption{First table}\tabularnewline}
]{mytable.csv}\par
}

{\centering
%\captionof{table}{Second table}
\pgfplotstabletypeset[
    header=has colnames,
    col sep=semicolon,
    read comma as period=true,
    display columns/0/.style={column type={l},string type}, 
    display columns/1/.style={sci,sci zerofill,sci sep align,},
    display columns/2/.style={sci,sci zerofill,sci sep align,},
    display columns/3/.style={column type={l},string type}, 
    display columns/4/.style={sci,sci zerofill,sci sep align,},
    display columns/5/.style={column type={l},string type}, 
    every head row/.style={before row=\caption{Second table}\tabularnewline}
]{mytable.csv}\par
}

{\centering
%\captionof{table}{Third table}
\pgfplotstabletypeset[
    header=has colnames,
    col sep=semicolon,
    read comma as period=true,
    display columns/0/.style={column type={l},string type}, 
    display columns/1/.style={sci,sci zerofill,sci sep align,},
    display columns/2/.style={sci,sci zerofill,sci sep align,},
    display columns/3/.style={column type={l},string type}, 
    display columns/4/.style={sci,sci zerofill,sci sep align,},
    display columns/5/.style={column type={l},string type},
    every head row/.style={before row=\caption{Third table}\tabularnewline}
]{mytable.csv}\par
}

\end{document}

enter image description here

Holene
  • 6,920