1

When I try to import a csv table from an external file that has both numbers and characters in the same column, siunitx package gives the following error.

Package siunitx Error: Invalid token 'n' in numerical input. ...olviii} & \num{\csvcolix} & \num{\csvcolx}}

Package siunitx Error: Invalid numerical input 'nan'. ...olviii} & \num{\csvcolix} & \num{\csvcolx}}

Can you please explain me who to fix it?

Below is the code I am trying fix. Note that there are nans in the 3rd row.

\documentclass{standalone}
\usepackage{csvsimple}
\usepackage{siunitx}

\begin{filecontents*}{datax.csv}
    SAE;Preston large;Preston medium;Preston small;Thornbury large;Thornbury medium;Thornbury small;Watsonia large;Watsonia medium;Watsonia small
    0.01;0.999719404401668;0.999894028145405;0.999925052593957;0.999724612270785;0.999895424470149;0.999952368552519;0.999801893445968;0.999835811093814;0.999939317307603
    0.02;0.99887728809391;0.999610604031798;0.999822693197714;0.998838278018596;0.999524047487632;0.999743728111286;0.999110837739707;0.999241442842171;0.999820408991234
    0.25;0.870257241788897;0.943192609889118;nan;0.852794258094785;0.926532048135534;nan;0.903983486684707;0.896993365388664;nan
\end{filecontents*}

\begin{document}
    \sisetup{round-mode=places, round-precision=4}
    \begin{tabular}{|l|l|l|l|l|l|l|l|l|l|}%
        
        \textbf{SAE} & \multicolumn{3}{c|}{\textbf{Preston}} &  \multicolumn{3}{c|}{\textbf{Thornbury}} & \multicolumn{3}{c|}{\textbf{Watsonia}} \\%
        & \textbf{Large} & \textbf{Medium} & \textbf{Small} & \textbf{Large} & \textbf{Medium} & \textbf{Small} & \textbf{Large} & \textbf{Medium} & \textbf{small}
        %specify table head
        \csvreader[head to column 
        names, separator=semicolon]{datax.csv}{}% use 
        %head of csv as column names
        {\\\hline\csvcoli & \num{\csvcolii } & \num{\csvcoliii} & 
            \num{\csvcoliv} & \num{\csvcolv} &  \num{\csvcolvi}  &  
            \num{\csvcolvii} & \num{\csvcolviii} &  \num{\csvcolix} & \num{\csvcolx}}% specify your coloumns here
    \end{tabular}


\end{document}
1

With siunitx's S type columns instead of l type columns and \num:

enter image description here

\documentclass{standalone}
\usepackage{csvsimple}
\usepackage{siunitx}

\begin{filecontents*}{datax.csv}
    SAE;Preston large;Preston medium;Preston small;Thornbury large;Thornbury medium;Thornbury small;Watsonia large;Watsonia medium;Watsonia small
    0.01;0.999719404401668;0.999894028145405;0.999925052593957;0.999724612270785;0.999895424470149;0.999952368552519;0.999801893445968;0.999835811093814;0.999939317307603
    0.02;0.99887728809391;0.999610604031798;0.999822693197714;0.998838278018596;0.999524047487632;0.999743728111286;0.999110837739707;0.999241442842171;0.999820408991234
    0.25;0.870257241788897;0.943192609889118;nan;0.852794258094785;0.926532048135534;nan;0.903983486684707;0.896993365388664;nan
\end{filecontents*}

\begin{document}
    \sisetup{round-mode=places, round-precision=4,table-format=1.4}
    \begin{tabular}{|S[table-format=1.2, round-mode=off]|*{9}{S|}}%

        \textbf{SAE} & \multicolumn{3}{c|}{\textbf{Preston}} &  \multicolumn{3}{c|}{\textbf{Thornbury}} & \multicolumn{3}{c|}{\textbf{Watsonia}} \\%
        & \textbf{Large} & \textbf{Medium} & \textbf{Small} & \textbf{Large} & \textbf{Medium} & \textbf{Small} & \textbf{Large} & \textbf{Medium} & \textbf{small}
        %specify table head
        \csvreader[head to column 
        names, separator=semicolon]{datax.csv}{}% use 
        %head of csv as column names
        {\\\hline\csvcoli & \csvcolii  & \csvcoliii & 
            \csvcoliv & \csvcolv &  \csvcolvi  &  
            \csvcolvii & \csvcolviii &  \csvcolix & \csvcolx}% specify your coloumns here
    \end{tabular}


\end{document}
| improve this answer | |

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.