3

I am trying to create a table with data from a .xslx file exported to .csv with pgfplotstable but I have trouble with the percentage sign. One of the columns in the header includes the percentage character and I keep getting the error

! Missing \endcsname inserted.

but this error only occurs when I try to name a header column with the percentage character (which is what I want!)

I am trying to get something like

--------------------
 Data   2%  Compare   
--------------------
 Data1  1      2
 Data2  3      4
--------------------

MWE that works: (Notice placement of \%)

\begin{filecontents*}{test01.csv}
Data,  2,    Compare
Data1, 1\%,  2
Data2, 3,    4
\end{filecontents*}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplotstable}
\usepackage{booktabs}

\begin{document}
\pgfplotstabletypeset[
    col sep=comma,
    string type,
    every head row/.style={before row=\toprule,after row=\hline},
    every last row/.style={after row=\hline},
    ]{test01.csv}
\end{document}

MWE that does not work:

\begin{filecontents*}{test001.csv}
Data,  2\%, Compare
Data1, 1,   2
Data2, 3,   4
\end{filecontents*}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplotstable}
\usepackage{booktabs}

\begin{document}
\pgfplotstabletypeset[
    col sep=comma,
    string type,
    every head row/.style={before row=\toprule,after row=\hline},
    every last row/.style={after row=\hline},
    ]{test001.csv}
\end{document}

As suggested by @egreg I have tried \begingroup\makeatletter\@makeother\% before \pgfplotstabletypeset but this does not work for the percentage character.

Therkel
  • 175
  • Are you free to adjust the data file? The problem is that 2\% is being used as a column name. – Andrew Swann Feb 13 '15 at 11:58
  • Do you have to put the percent character there? You can add it later using column/<column name>/column name=2\% where column name being whatever you wish 2p,2 etc. – percusse Feb 13 '15 at 12:07
  • 1
    I can fortunately edit the header of the data file. So I give the troublesome column header a dump name (2p) and rename it hereafter with columns/2p/.style={column name={2\%}? This seems to work! – Therkel Feb 13 '15 at 12:58

1 Answers1

2

You can add it later using column/<column name>/column name=2\% where column name being whatever you wish 2p,2 etc.

percusse
  • 157,807