5

First, I am fresh new with the PGFPlotTable package! I have the following CSV file that I would like to plot in a LaTeX table:

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
[...]

Almost everything works fine with numeric columns, but I cannot compile LaTeX document when I include the first column. I have read the documentation and take a tour of TeX.SO related posts but I could not find any relevant solution.

My include code is the following:

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

This code leads to the following error when LaTeX try to parse it:

 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'..

It looks like PGFPlotsTable does not notice the string type style argument and try to cast it into float number which raise a conversion error.

What I have tried so far:

  • Enclose timestamp with quotes, does not work;
  • Remove the table environment that wraps the include and all the features in it, it leads to the same error, it does not seem to have any effect;
  • Remove the header=has colnames argument which I think is not necessary as long as I name my columns, I get the same error

How must I force PGFPlotsTable to consider my column as text? What is going wrong with my code?

Update:

As suggested by fmetz, I have enclosed my timestamps with curly-braces, now the CSV file has the following form, but it did not solve my problem:

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
[...]

The error remains:

! 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'..
5
  • Did you try to enclose the timestamp in braces like {2015-09-01 00:00:00} ?
    – fmetz
    Nov 1, 2015 at 12:44
  • @fmetz unfortunately it does not work, I have updated the post
    – jlandercy
    Nov 1, 2015 at 12:57
  • 1
    Remove dec sep align, fonts by sign={}{\color{red}},
    – user11232
    Nov 1, 2015 at 12:58
  • 1
    @HarishKumar, worked, could you explain why this happens. May you write down the solution and I accept it. Thank you for debugging the code.
    – jlandercy
    Nov 1, 2015 at 13:02
  • 1
    You can move the problematic styles in the column style so that pgfplots doesn't try to use it for the string column columns/meanfinalfloatvalue/.style={column name={$\bar{x}$},fixed,zerofill,precision=3, dec sep align, fonts by sign={}{\color{red}},}, Nov 1, 2015 at 13:06

1 Answer 1

4

When given as a general option, dec sep align will spoil your alignment, and fonts by sign={}{\color{red}} is expecting every number in every column as a floating number which is not true in first column. So move these two options in to the styles of individual columns where they are needed.

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .