I like the pgfplotstable package for reading and plotting tables but handling of strings and values (especially when strings contain spaces) drives me crazy…
I often use a table as shown here:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{pgfplotstable}
\usepackage{booktabs}
%
\begin{filecontents*}{table.dat}
a b c d e f g
1 Item1 alpha m 1 1 10
2 Item2 beta s 1.0 11 20
3 Item3 gamma kg 10.0 111 30
4 Item4 omega deg 10.00 1111 40
5 Item5 xi \% 10.99 11111 50
\end{filecontents*}
\begin{document}
\begin{figure}[hp]
\pgfplotstableread{testMod.dat}\loadTestTable
\pgfplotstabletypeset[
% header=false,
brackets/.style={%
postproc cell content/.append style={/pgfplots/table/@cell content/.add={\relax[}{]}},
},
greek/.style={%
postproc cell content/.append style={/pgfplots/table/@cell content/.add={\textbackslash}{}},
},
column type=r,
columns/a/.style={string type},
columns/b/.style={string type,column type=l},
columns/c/.style={string type,column type=l},
columns/d/.style={string type,column type=l},
columns/c/.append style={greek},
columns/d/.append style={brackets},
fixed,
fixed zerofill,
precision=2,
% dec sep align,
every head row/.style={%
output empty row,
before row={%
\toprule
No. & Item & Symbol & Unit & Column1 & Column2 & Column3\\
},
after row=\midrule,
},
every last row/.style={%
after row=\bottomrule}]{table.dat}
\end{figure}
\end{document}
I need to have two things:
- spaces in strings, i.e. 'Item of first row'
- set greek symbols automatically (comment out line 'columns/c/.style={string type,column type=l},' did not work
Thanks for any advice!
Paul
Best Answer
As Jake noted, it is the notorious CSV regexp problem of finding which space is escaped which is used for delimiters etc. So if you want spaces to be respected then use something else for delimiter. But make sure you add
trim cells
option otherwise your data and column names become whitespace-sensitive.For the Greek characters, you can use
$\csname #1 \endcsname$
syntax which makes#1
a control sequence, say$\csname alpha \endcsname
becomes\alpha
. (c)ontrol (s)equence name -->\csname