pgfplotstable 和 longtable 表计数器问题/标题定位

pgfplotstable 和 longtable 表计数器问题/标题定位

考虑以下使用pgfplotstablelongtable输出一些csv文件内容的 MWE。每添加一个表,表计数器就会增加两次。为什么?

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

在此处输入图片描述

答案1

您已经longtable在内部使用了table,但它没有什么用,因为table它是一个框,所以不能分割,然后是一个表格\caption,并且longtable两者都增加了表格标题。

要么只使用 longtable,然后\caption在内部使用longtable,要么使用\caption内部table并使用tabular

答案2

这个问题已经(某种程度上)得到了回答:带有 longtable 和 pgfplotstabletypeset 的标题

问题在于标题的定位,必须将其添加为

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

在宏的可选参数中\pgfplotstabletypsetcaptionof不起作用(并且不需要)。

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

在此处输入图片描述

相关内容