1

I have searched for solution to my problem on using pgfplotstable, but I didn't find nothing useful.

I'm using pgfplotstable to import csv data into my latex code. My table has four columns. The first one is has string data and the others has numeric values.

I indicated the column type for the first column string, then get the following message - error(1):

! Missing $ inserted. $ l.17 ]{teste.csv}

The data are in the file teste.csv

If I remove the string type style from the first column, I get the following error (2):

! Package PGF Math Error: Could not parse input 'B030_01' as a floating point number, sorry. The unreadable part was near 'B030_01'..

My latex code:

\documentclass{article}

\usepackage{pgfplotstable}
\usepackage{array}

\usepackage[utf8]{inputenc}

\pgfplotsset{compat=1.9}

%\pgfplotstableread[col sep=tab]{teste.csv}\mytable

\begin{document}

\pgfplotstabletypeset[col sep=tab,
    columns={Instance,CAP,CUSTO,TIME}
    columns/Instance/.style={string type}   % if commented get error 2, else get error 1
]{teste.csv}

\end{document}

My data table:

Instance    CAP CUSTO   TIME
B030_01 3   15673   0.136264
B030_02 3   16732   0.143577
...
B030_28 8   99998.5 1.28447
B030_29 17  93604.5 1.110965
B030_30 17  96460.5 1.19836

Maybe, the error could be very simple, but until now I didn't figure it out.

  • Welcome to TeX.SX! – Heiko Oberdiek Sep 30 '15 at 13:39
  • Thank you. I've fixed the problem. In the date file the values of the first columns are B030_<id> , but this value must be B030_ 30. – Romerito Sep 30 '15 at 13:49
2

It is because the string type wants text mode and sees the underscore which is a mathmode char and if you don't use string type it tries to keep it as a number but it is not. Instead you can search and replace this with string compatible version of _. Here I just simplified the example to an inline table:

\pgfplotstabletypeset[
    columns={Instance,CAP,CUSTO,TIME},
    columns/Instance/.style={string type,string replace*={_}{\textunderscore}}
]{
Instance CAP CUSTO TIME
B030_01 3   15673   0.136264
B030_02 3   16732   0.143577
B030_28 8   99998.5 1.28447
B030_29 17  93604.5 1.110965
B030_30 17  96460.5 1.19836
}

enter image description here

  • Perfect! Thanks! I've changed the data file, but this solutions is much better. – Romerito Sep 30 '15 at 13:58
2

The first column contains _, which is serves as special character for a subscript in math mode. Therefore, TeX expects math mode and complains with an error.

This can be solved by reading the first column in verbatim mode, which can be set by type verb string type:

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{pgfplotstable}
\usepackage{array}

\usepackage[utf8]{inputenc}

\pgfplotsset{compat=1.9}

\begin{document}

\pgfplotstabletypeset[col sep=tab,
    columns={Instance,CAP,CUSTO,TIME},
    columns/Instance/.style={verb string type},
]{teste.csv}

\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.