3

I don't understand why it gives me the error Extra }, or forgotten $. <recently read> } in the part ...entoIdraulico & \RendimentoMeccanico } \\ if I change in S the last c of the part \begin{tabular}{SS[table-format = 9.0]S[table-format = 9.0]S[table-format = 9.0]S[table-format = 1.4]c}. Could someone explain me what I'm wrong or what should I do in order to solve that problem and have elements of the last column aligned by decimal separator?

\documentclass{article}
\usepackage{booktabs,multirow,siunitx,csvsimple}

\begin{filecontents*}{input.csv}
    Portata,PotenzaDisponibile,PotenzaIndicata,PotenzaMeccanica,RendimentoIdraulico,RendimentoMeccanico
    0,0,0,,0.7175,
    1,7840000,5849424,4049424,0.7461,0.692277393
    2,15680000,12112800,10312800,0.7725,0.851396869
    3,23520000,18738384,16938384,0.7967,0.903940489
    4,31360000,25674432,23874432,0.8187,0.929891341
    5,39200000,32869200,31069200,0.8385,0.945237487
    6,47040000,40270944,38470944,0.8561,0.955302761
    7,54880000,47827920,46027920,0.8715,0.962365079
    8,62720000,55488384,53688384,0.8847,0.967560778
    9,70560000,63200592,61400592,0.8957,0.971519254
    10,78400000,70912800,69112800,0.9045,0.974616712
    11,86240000,78573264,76773264,0.9111,0.977091444
    12,94080000,86130240,84330240,0.9155,0.979101417
    13,101920000,93531984,91731984,0.9177,0.980755246
    14,109760000,100726752,98926752,0.9177,0.982129872
    15,117600000,107662800,105862800,0.9155,0.983281133
    16,125440000,114288384,112488384,0.9111,0.984250368
    17,133280000,120551760,118751760,0.9045,0.985068654
    18,141120000,126401184,124601184,0.8957,0.985759627
    19,148960000,131784912,129984912,0.8847,0.98634138
    20,156800000,136651200,134851200,0.8715,0.986827778
\end{filecontents*}

\begin{document}
    \begin{table}[htp]
    \caption{Valori}
        \begin{tabular}{SS[table-format = 9.0]S[table-format = 9.0]S[table-format = 9.0]S[table-format = 1.4]c}
            \toprule
                \multirow{2}*{Portata} & \multicolumn{3}{c}{Potenza} & \multicolumn{2}{c}{Rendimento} \\
                \cmidrule(lr){2-4} \cmidrule(lr){5-6} & {Disponibile} & {Indicata} & {Meccanica} & {Idraulico} & {Meccanico} \\
                {(m\textsuperscript{3}/s)} & {(W)} & {(W)} & {(W)} & & %
                \csvreader[head to column names]{input.csv}{}{\\ \midrule \Portata & \PotenzaDisponibile & \PotenzaIndicata & \PotenzaMeccanica & \RendimentoIdraulico & \RendimentoMeccanico } \\
            \bottomrule
        \end{tabular}
    \end{table}
\end{document}

enter image description here

Thanks in advance.

1

Also the answers for see csvsimple and siunitx

There is some detection problem at the begin or end of a scanned line with siunitx. According to the table format, siunitx tries to detect the content of one cell for formatting. Unfortunately, there are also some invisible remains of the file reading process which seems to disturb the overall detection.

In your case, the last cell contains the problematic part. In my answer code, I change the place for \\ to use some key setting features available, but the problem is just shifted to the first cell.

The real solution is to change the code for the problematic cell. Here, the first column is made r (could also be l or c) and the format is done inside the cell by

\tablenum{\Portata}

Now, siunitx only sees (and formats) what is should see.

enter image description here

The full code is:

\documentclass{article}
\usepackage{booktabs,multirow,siunitx,csvsimple}


\begin{filecontents*}{input.csv}
    Portata,PotenzaDisponibile,PotenzaIndicata,PotenzaMeccanica,RendimentoIdraulico,RendimentoMeccanico
    0,0,0,,0.7175,
    1,7840000,5849424,4049424,0.7461,0.692277393
    2,15680000,12112800,10312800,0.7725,0.851396869
    3,23520000,18738384,16938384,0.7967,0.903940489
    4,31360000,25674432,23874432,0.8187,0.929891341
    5,39200000,32869200,31069200,0.8385,0.945237487
    6,47040000,40270944,38470944,0.8561,0.955302761
    7,54880000,47827920,46027920,0.8715,0.962365079
    8,62720000,55488384,53688384,0.8847,0.967560778
    9,70560000,63200592,61400592,0.8957,0.971519254
    10,78400000,70912800,69112800,0.9045,0.974616712
    11,86240000,78573264,76773264,0.9111,0.977091444
    12,94080000,86130240,84330240,0.9155,0.979101417
    13,101920000,93531984,91731984,0.9177,0.980755246
    14,109760000,100726752,98926752,0.9177,0.982129872
    15,117600000,107662800,105862800,0.9155,0.983281133
    16,125440000,114288384,112488384,0.9111,0.984250368
    17,133280000,120551760,118751760,0.9045,0.985068654
    18,141120000,126401184,124601184,0.8957,0.985759627
    19,148960000,131784912,129984912,0.8847,0.98634138
    20,156800000,136651200,134851200,0.8715,0.986827778
\end{filecontents*}

\begin{document}
    \begin{table}[htp]
    \caption{Valori}
        \begin{tabular}{rS[table-format = 9.0]S[table-format = 9.0]S[table-format = 9.0]S[table-format = 1.4]S[table-format = 1.9]}
            \toprule
                \multirow{2}*{Portata} & \multicolumn{3}{c}{Potenza} & \multicolumn{2}{c}{Rendimento} \\
                \cmidrule(lr){2-4} \cmidrule(lr){5-6} & {Disponibile} & {Indicata} & {Meccanica} & {Idraulico} & {Meccanico} \\
                {(m\textsuperscript{3}/s)} & {(W)} & {(W)} & {(W)} & & \\\midrule
                \csvreader[head to column names,late after line=\\\midrule,late after last line=\\\bottomrule]{input.csv}{}{%
                  \tablenum{\Portata} & \PotenzaDisponibile & \PotenzaIndicata & \PotenzaMeccanica & \RendimentoIdraulico & \RendimentoMeccanico
                }
        \end{tabular}
    \end{table}
\end{document}

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.