4

I've been trying to find the right way to load angles from CSV file with pgfplotstable, format them using siunitx's \ang{} command and display them using pgfplotstable. My idea was to pass the data in the postprocessing stage to the \ang command but I get the following error:

Runaway argument? \l__siunitx_number_arg_tl \tl_map_function:NN \l__siunitx_number_arg_tl \ETC. ! File ended while scanning use of __siunitx_number_in_parse_relation:w.

If I remove the \ang command, everything compiles so I presume that I'm formatting the numbers in a bad way. Is there a proper way to load angular data from the .csv with pgfplotstable?

My MWE is given below:

\documentclass[margin=5mm,preview]{standalone}
\usepackage{siunitx}
\usepackage{booktabs} 
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.13}
\usepackage{filecontents}                              

\begin{filecontents*}{mytable.csv}
angle, magnitude
0,1
5;15;0,2
10;5;5,4
\end{filecontents*}

\begin{document}
\pgfplotstabletypeset[
    col sep=comma, 
    string type,
    header=true,
   every head row/.style={before row=\toprule,after row=\midrule},
   every last row/.style={after row=\bottomrule},
display columns/angle/.style={string type,postproc cell content/.code={\ang{#1}}},  
display columns/magnitude/.style={column name={$a$}},
]{mytable.csv}
\end{document}

The result is given below:

result

Edit 1: I've used column names in the display columns/../.style lines and the error has gone but the data is not processed at all.

Edit 2: I've added the result of the previous edit.

  • mytable.csv is in the MWE, it is made using the filecontents package. – Budo Zindovic May 24 '17 at 12:47
4

There are a few attention points to make it work.

  1. display columns is used with column index. It is helpful when the column name is strange or you don't want to remember. Hence you need numbering. It starts from 0.
  2. When you are implementing nested style or code arguments inside each other you need to double the # characters to mean what the output is. If you have

    a/.style={b/.style={c=#1}}
    

    and you supply a=red then you mean b/.style={c=red} because that is the input to a. Instead if you want to define b/.style={c=#1} inside the style definition of a then you need a/.style={b/.style={c=##1}}

  3. post processing executes code does not replace the cell contents. You need to execute some code to change the cell contents.

So it becomes;

\pgfplotstabletypeset[
    col sep=comma, 
    string type,
    header=true,
   every head row/.style={before row=\toprule,after row=\midrule},
   every last row/.style={after row=\bottomrule},
display columns/0/.style={string type,
    postproc cell content/.code={%
        \pgfkeyssetvalue{/pgfplots/table/@cell content}{\ang{##1}}%
    }
}, 
display columns/1/.style={column name={$a$}},
]{angle, magnitude
0,1
5;15;0,2
10;5;5,4
}

enter image description here

  • 1
    Dear @percusse, this is really superb solution and very flexible. In my original post, I've used the same as in your point 1) but have changed in my Edit 1. I've been testing with the point number 2) but that wasn't a solution as I lacked the solution from your point 3). – Budo Zindovic May 24 '17 at 21:44

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.