考虑以下使用pgfplotstable
和longtable
输出一些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}
在宏的可选参数中\pgfplotstabletypset
。captionof
不起作用(并且不需要)。
\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}