使用 booktabs+siunits 将缺失数字视为零

使用 booktabs+siunits 将缺失数字视为零

我正在学习在表格环境中使用该siunits包来按小数点对齐数字。

我正在看伯纳德的问题,当我尝试将其代码实现到我的表中时,我得到了一个missing number treated as zero

! Missing number, treated as zero.
<to be read again> 
                   c
l.15    \multicolumn{c}{1}{$\theta$ ($^{\circ}$)}
                                                & \multicolumn{c}{1}{$\sigma...
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

这是我的 MWE

\documentclass[11pt]{article}
\usepackage{siunitx}
\usepackage{booktabs}


\begin{document}

   \begin{tabular}{ l*{5}{S[table-format=4.2, table-number-alignment=center]}}
    \toprule 
    \multicolumn{c}{1}{$\theta$ ($^{\circ}$)} & \multicolumn{c}{1}{$\sigma_x^' $ (kips)} & \multicolumn{c}{1}{$\sigma_y^'$ (kips)} & \multicolumn{c}{1}{$\tau_{xy}^'$ (kips)} & \multicolumn{c}{1}{$2\theta_p$ ($^{\circ}$)}\\\midrule
    0 & 10 & 0 & 6 & 50.1944\\
    15 & 12.3301 & -2.3301 & 2.6962 & 20.1944\\
    30 & 12.6962 & -2.6962 & -1.3301 & 350.1944\\
    45 & 11 & -1 & -5 & 320.1944\\
    60 & 7.6962 & 2.3038 & -7.3301 & 290.1944\\
    75 & 3.6699 & 6.3301 & -7.6962 & 260.1944\\
    90 & 0 & 10 & -6 & 230.1944\\
    105 & -2.3301 & 12.3301 & -2.6962 & 200.1944\\
    120 & -2.6962 & 12.6962 & 1.3301 & 170.1944\\
    135 & -1 & 11 & 5 & 140.1944\\
    150 & 2.3038 & 7.6962 & 7.3301 & 110.1944\\
    165 & 6.3301 & 3.6699 & 7.6962 & 80.1944\\
    180 & 10 & 0 & 6 & 50.1944\\
    \bottomrule \end{tabular}
\end{document}

答案1

正如 Johannnes_B 在他的评论中所说,命令的正确语法\multicolumn

\multicolumn{cols}{pos}{text}

其中 cols=列数、pos=对齐方式和 text=内容。但在您的情况下,将内容放在里面就足够了{ }

table-format=4.2意思是4个整数,2个小数,我根据各列的内容改了一下。

我想补充一点,在您的列定义中,您有 6 列(一l和五S),而您的表只有 5 列。

此外$\sigma_x^'$是不正确的,'应该放在内{ },但我认为你只需要$\sigma_x'$

\documentclass[11pt]{article}
\usepackage{siunitx}
\sisetup{table-number-alignment=center}
\usepackage{booktabs}

\begin{document}    
    \begin{tabular}{
            S[table-format = 3]
            *2{S[table-format = -2.4]}
            S[table-format = -1.4]
            S[table-format = 3.4]
        }
        \toprule 
        {$\theta$ ($^{\circ}$)} &
        {$\sigma_x'$ (kips)} &
        {$\sigma_y'$ (kips)} & 
        {$\tau_{xy}'$ (kips)} & 
        {$2\theta_p$ ($^{\circ}$)}\\
        \midrule
        0 & 10 & 0 & 6 & 50.1944\\
        15 & 12.3301 & -2.3301 & 2.6962 & 20.1944\\
        30 & 12.6962 & -2.6962 & -1.3301 & 350.1944\\
        45 & 11 & -1 & -5 & 320.1944\\
        60 & 7.6962 & 2.3038 & -7.3301 & 290.1944\\
        75 & 3.6699 & 6.3301 & -7.6962 & 260.1944\\
        90 & 0 & 10 & -6 & 230.1944\\
        105 & -2.3301 & 12.3301 & -2.6962 & 200.1944\\
        120 & -2.6962 & 12.6962 & 1.3301 & 170.1944\\
        135 & -1 & 11 & 5 & 140.1944\\
        150 & 2.3038 & 7.6962 & 7.3301 & 110.1944\\
        165 & 6.3301 & 3.6699 & 7.6962 & 80.1944\\
        180 & 10 & 0 & 6 & 50.1944\\
        \bottomrule 
    \end{tabular}
\end{document}

在此处输入图片描述

相关内容