I have some data in a .csv
file that I would like to typeset with a combination of pgfplotstable
and siunitx
. Consider the following (not so extremely minimal) MWE who throws the error
Undefined control sequence. \micro ->\ERROR l.49 ]{mytable.csv}\par
Why does this go wrong?
\documentclass[norsk,10pt,a4paper]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,parskip,url,xcolor,tabularx,array,adjustbox,booktabs}
\usepackage[showframe]{geometry}
\usepackage[hang,bf,small]{caption}
\usepackage{capt-of,pgfplotstable}
\usepackage{siunitx}
\sisetup{exponent-product = {\cdot},output-decimal-marker={,}, per-mode=symbol}
\begin{filecontents*}{mytable.csv}
Chem.; Avg. Conc.; Avg. Conc. Norm.; Conc. Unit; Mass sum; Mass unit
ammonium; 159083,33; 114450,21; \micro\gram\per\liter; 2839,463; \kilo\gram
\end{filecontents*}
\begin{document}
Some text here
\captionof{table}{Some caption text}
{\centering
\pgfplotstabletypeset[%
col sep=semicolon,
read comma as period=true,
header=has colnames,
every head row/.style={
before row={\toprule},
after row={\midrule},
every last row/.style={
after row=\bottomrule},
},
display columns/0/.style={%
string type, column type=l,%
},%
display column/1/.style={
},
display column/2/.style={
},
display column/3/.style={%
string type, column type={s},%
},%
display column/4/.style={
},
display column/5/.style={%
string type, column type={s},
},%
]{mytable.csv}\par
}
\end{document}
Best Answer
Your MWE has bunch of errors, the most of them I succeeded to eliminate, so the MWE is now at least possible to compile ...
Edit (1): Meanwhile I dug through
pgfplotstable
manual and SE in searching of not resolved issues in my answer. This was quite fruitful; I was able to found my mistakes, which I introduced when correcting errors in your MWE ... The resulting new code and image of obtained table are given below.As you can see, in table I introduced
S
column type of column and usedsiunitx
engine for number formatting in columns.Warning: Due to lengthy column heads, the table is wider than usual
\textwidth
inarticle
document-class.Edit (2): Meanwhile, Stefan Pinnow in his comment described alternative solution (which for unknown reason didn't work before, now I cannot remember, what was wrong :-( ). However, corrected code is given below.
Result is the same as before!