0

Similar to this: csvsimple and siunitx

Could there be a similar workaround but with \csvlinetotablerow instead of explicitly write every \csvcoli, \csvcolii ?

Here's my MWE :

\documentclass[varwidth=\maxdimen]{standalone}

\usepackage{csvsimple}
\usepackage{siunitx}

\begin{filecontents*}{data.csv}
A,B,C
1.23,4.5,67.89
1.2,34.56,7.89
\end{filecontents*}

\begin{document}

\csvreader[
    tabular={SSS} % if I change it to {cSS}, it works flawlessly
]{data.csv}{}{\csvlinetotablerow}

\end{document}
1

1 Answer 1

2

From the csvsimple document, page #50

Special care is needed if the first or the last column is to be formatted with the column type S. The number detection of siunitx is disturbed by the line reading code of csvsimple which actually is present at the first and last column. To avoid this problem, the utilization of \tablenum is appropriate.

Alternatively, a very nifty workaround suggested by Enrico Gregorio is to add an invisible dummy column with c@{} as first column and @{}c as last column.

c

\documentclass{article}

\usepackage[l3]{csvsimple}
\usepackage{siunitx}    

\begin{filecontents*}{data.csv}
    A,B,C
    1.23,4.5,67.89
    1.2,34.56,7.89
\end{filecontents*}

\begin{filecontents*}{data2.csv}
,A,B,C,
,1.23,4.5,67.89,
,1.2,34.56,7.89,
\end{filecontents*}

\begin{document}
    
    Using \verb|\tablenum|\bigskip
    
    \csvreader[
    head to column names,
    tabular={ccc} % 
    ]{data.csv}{}{\tablenum{\A} &\tablenum{\B}& \tablenum{\C}}
    
    \bigskip
    
    Using Enrico Gregorio suggestion    \bigskip
        
    \csvreader[
    head to column names,
    tabular={c@{}SSS@{}c} % 
    ]{data.csv}{}{&\A & \B & \C &}  \bigskip
    
    Now with \verb|\csvlinetotablerow| (different data set)\bigskip
        
    \csvreader[
    tabular={c@{}SSS@{}c} %
    ]{data2.csv}{}{\csvlinetotablerow}          

\end{document}

In a nutshell, to use S columns along with E. Gregorio's suggestion and \csvlinetotablerow, an empty first and last column must be added to the original data set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .