首先,我对 PGFPlotTable 包很熟悉!我有以下 CSV 文件,我想将其绘制在 LaTeX 表中:
truncatedtime;meanfinalfloatvalue;floatvaluedifference;datap2count;expecteddatap2count;performance
2015-09-01 00:00:00;0.0375;0.0;48;48;1.0
2015-09-02 00:00:00;-0.247916666666667;0.0;48;48;1.0
2015-09-03 00:00:00;0.364583333333333;0.0;48;48;1.0
2015-09-04 00:00:00;0.397916666666667;0.0;48;48;1.0
2015-09-05 00:00:00;0.310416666666667;0.0;48;48;1.0
[...]
几乎所有东西都可以在数字列下正常工作,但当我包含第一列时,我无法编译 LaTeX 文档。我已阅读文档并浏览了 TeX.SO 相关帖子,但找不到任何相关解决方案。
我的包含代码如下:
\begin{table}[!ht]
\centering
\pgfplotstabletypeset[
col sep=semicolon,
columns={truncatedtime,meanfinalfloatvalue,floatvaluedifference,datap2count,expecteddatap2count,performance},
columns/truncatedtime/.style={string type},
columns/meanfinalfloatvalue/.style={column name={$\bar{x}$},fixed,zerofill,precision=3},
columns/floatvaluedifference/.style={column name={$\Delta\bar{x}$},fixed,zerofill,precision=3},
columns/datap2count/.style={column name={$n_\mathrm{exp}$}},
columns/expecteddatap2count/.style={column name={$n_\mathrm{th}$}},
columns/performance/.style={column name={$\eta$},fixed,zerofill,precision=3},
header=has colnames,
font=\footnotesize,
dec sep align,
fonts by sign={}{\color{red}},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}
]{tables/Aggregate_day_dT_003_T1M003.csv}
\caption{Aggregates (day) for Channel dT:003/T1M003 (MET)\protect\footnotemark}
\label{tab:Aggregates_day_dT:003/T1M003 (MET)}
\end{table}
当 LaTeX 尝试解析此代码时,会导致以下错误:
Package PGF Math Error: Could not parse input '2015-09-25 00:00:00' as a floa
ting point number, sorry. The unreadable part was near '-09-25 00:00:00'..
它看起来PGFPlotsTable
没有注意到string type
样式参数并尝试将其转换为浮点数,从而引发转换错误。
到目前为止我已经尝试过:
- 用引号括起时间戳,不起作用;
- 删除
table
包装包含的内容的环境及其中的所有功能,它会导致相同的错误,似乎没有任何效果; - 删除
header=has colnames
我认为不必要的参数,只要我命名我的列,我就会得到同样的错误
我必须如何强制 PGFPlotsTable 将我的列视为文本?我的代码出了什么问题?
更新:
按照建议fmetz
,我用花括号将时间戳括起来,现在 CSV 文件具有以下格式,但这并不能解决我的问题:
truncatedtime;meanfinalfloatvalue;floatvaluedifference;datap2count;expecteddatap2count;performance
{2015-09-01};0.0375;0.0;48;48;1.0
{2015-09-02};-0.247916666666667;0.0;48;48;1.0
{2015-09-03};0.364583333333333;0.0;48;48;1.0
{2015-09-04};0.397916666666667;0.0;48;48;1.0
{2015-09-05};0.310416666666667;0.0;48;48;1.0
{2015-09-06};0.39375;0.0;48;48;1.0
{2015-09-07};0.414583333333333;0.0;48;48;1.0
{2015-09-08};0.375;0.0;48;48;1.0
[...]
错误依然存在:
! Package PGF Math Error: Could not parse input '2015-09-06' as a floating poin
t number, sorry. The unreadable part was near '-09-06'..
答案1
当作为一般选项给出时,dec sep align
会破坏您的对齐,并且fonts by sign={}{\color{red}}
期望每一列中的每个数字都是浮点数,而第一列则不是这样。因此,将这两个选项移到需要它们的单个列的样式中。
\documentclass{article}
\usepackage{pgfplotstable,array,booktabs}
\begin{document}
\begin{table}[!ht]
\centering
\pgfplotstabletypeset[
col sep=semicolon,
columns={truncatedtime,meanfinalfloatvalue,floatvaluedifference,datap2count,expecteddatap2count,performance},
columns/truncatedtime/.style={string type},
columns/meanfinalfloatvalue/.style={dec sep align,fonts by sign={}{\color{red}},column name={{$\bar{x}$}},fixed,zerofill,precision=3},
columns/floatvaluedifference/.style={column name={$\Delta\bar{x}$},dec sep align,fixed,zerofill,precision=3},
columns/datap2count/.style={dec sep align,column name={$n_\mathrm{exp}$}},
columns/expecteddatap2count/.style={dec sep align,column name={$n_\mathrm{th}$}},
columns/performance/.style={dec sep align,column name={$\eta$},fixed,zerofill,precision=3},
header=has colnames,
font=\footnotesize,
%dec sep align,
% fonts by sign={}{\color{red}},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule}
]{
truncatedtime;meanfinalfloatvalue;floatvaluedifference;datap2count;expecteddatap2count;performance
2015-09-01 00:00:00;0.0375;0.0;48;48;1.0
2015-09-02 00:00:00;-0.247916666666667;0.0;48;48;1.0
2015-09-03 00:00:00;0.364583333333333;0.0;48;48;1.0
2015-09-04 00:00:00;0.397916666666667;0.0;48;48;1.0
2015-09-05 00:00:00;0.310416666666667;0.0;48;48;1.0
}
\caption{Aggregates (day) for Channel dT:003/T1M003 (MET)\protect\footnotemark}
\label{tab:Aggregates_day_dT:003/T1M003 (MET)}
\end{table}
\end{document}