1

I am learning to use the siunits package in a tabular environment to align number by their decimal point.

I was watching the top answer given in this question by Bernard and when I tried to implement its code into my table but I get a 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.)

this is my 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}
  • Why don't you post a minimal example? The first compile run gave me an error message highlighting \multicolumn{c}{1}{$\theta$ ($^{\circ}$)} The syntax is wrong. First the number of columns, then the alignment. It should be \multicolumn{1}{c}{content}. – Johannes_B Apr 8 '18 at 5:14
  • Also, it doesn't make any sense to have just one column for a multicol. You are probably looking for {content}. – Johannes_B Apr 8 '18 at 5:16
  • You should learn how to use a package by reading the documentation. 4.2 is wrong for all your columns. Only a documentation can clearly and up to date explain what the parameters mean. – Johannes_B Apr 8 '18 at 5:23
3

As Johannnes_B said in his comments, the correct syntax of \multicolumn command is

\multicolumn{cols}{pos}{text}

where cols=number of columns, pos=alignment, and text=content. but is your case it is enough to put the content within { }.

table-format=4.2 means 4 integers and 2 decimals, I changed it according to the content of the various columns.

I would like to add that in your column definition you have 6 columns (one l and five S), whereas your table only has 5 columns.

Moreover $\sigma_x^'$ is not correct, the ' should be put within { }, but I think you simply need $\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}

enter image description here

  • @PaulLara You're welcome, thank you for accepting my answer! – CarLaTeX Apr 9 '18 at 19:22

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.