csvsimple 和 siunitx 的最后一列问题

csvsimple 和 siunitx 的最后一列问题

我不明白为什么如果我更改最后Extra }, or forgotten $. <recently read> }一部分,它会给我错误。有人能解释一下我错在哪里吗?或者我应该怎么做才能解决这个问题,让最后一列的元素按小数点分隔符对齐?...entoIdraulico & \RendimentoMeccanico } \\Sc\begin{tabular}{SS[table-format = 9.0]S[table-format = 9.0]S[table-format = 9.0]S[table-format = 1.4]c}

\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}

在此处输入图片描述

提前致谢。

答案1

另请参阅答案csvsimple 和 siunitx

扫描行的开头或结尾存在一些检测问题siunitx。根据表格格式,siunitx尝试检测一个单元格的内容以进行格式化。不幸的是,文件读取过程中还存在一些不可见的残留,这似乎会干扰整体检测。

您的情况是最后一个单元格有问题。在我的答案代码中,我更改了位置以\\使用一些可用的按键设置功能,但问题只是转移到了第一个单元格。

真正的解决方案是更改有问题的单元格的代码。在这里,第一列被创建r(也可以是lc),并且格式在单元格内完成

\tablenum{\Portata}

现在,siunitx仅看到(和格式化)应该看到的内容。

在此处输入图片描述

完整代码如下:

\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}

相关内容