[Tex/LaTex] Creating a table from CSV file with strings

csvtables

I want to create a table from a CSV file in LaTex. I am able to do it with numbers here but creating table for strings such as abbrevions does not work. What is the problem?

enter image description here

MVE

This example fires error "Package PGF Math Error: Could not parse input '…' as a floating point number, sorry."

\documentclass{standalone}
\usepackage{pgfplotstable,filecontents}
\pgfplotsset{compat=1.9}% supress warning

\begin{filecontents*}{test.csv}
Abbreviation, Description
ACG, Azeri Chirag Guneshli
bcm, Billion cubic meters
BTC, Baku Tbilisi Ceyhan
CIA, Central Intelligence Agency
Btu, British thermal unit
CAC, Central Asia Center
EU, European Union
LNG, Liquified Natural Gas
NATO, North Atlantic Treaty Organization
OMV, Österreichische Mineralölverwaltung
\end{filecontents*}

\begin{document}
\pgfplotstabletypeset[col sep=comma, columns={Abbreviation,Description}]{test.csv}
\end{document}

Best Answer

Add the string type option:

enter image description here

Notes:

  • To control the alignment of each row you can specify the style for each row.

    columns/Abbreviation/.style={column type=l},
    columns/Description/.style={column type=l},
    

    Alternatively you can set the alignment for all columns via column type=l.

  • To add the horizontal lines, I used the booktabs package and the every head row and every last row keys.

Code:

\documentclass[border=5pt]{standalone}
\usepackage{booktabs}

\usepackage{pgfplotstable}
\pgfplotsset{compat=1.9}% supress warning


%\usepackage{filecontents}% <-- commented to prevent overwriting fuel
\begin{filecontents*}{test.csv}
Abbreviation, Description
ACG, Azeri Chirag Guneshli
bcm, Billion cubic meters
BTC, Baku Tbilisi Ceyhan
CIA, Central Intelligence Agency
Btu, British thermal unit
CAC, Central Asia Center
EU, European Union
LNG, Liquified Natural Gas
NATO, North Atlantic Treaty Organization
OMV, Österreichische Mineralölverwaltung
\end{filecontents*}

\begin{document}
\pgfplotstabletypeset[
    string type, 
    col sep=comma, 
    columns={Abbreviation,Description},
    columns/Abbreviation/.style={column type=l},
    columns/Description/.style={column type=l},
    every head row/.style={before row=\toprule,after row=\cmidrule(lr){1-1}\cmidrule(lr){2-2}},
    every last row/.style={after row=\bottomrule}
    ]{test.csv}
\end{document}