3

I am trying to align numbers on decimal in tabular. I have found some information here:align to decimal point in the table. However, when I adopt that code into my table, it gives an error:

! Package array Error: Illegal pream-token (S[table-format=-1.3, table-space-text-post=***]@{}): `c' used. 

I do not understand why it creates the error above, can anybody help me?

Here is my latex code:

  \begin{table*}[htb]
    \centering  
    \begin{tabular}{
    @{}|l|ccc|ccc|{S[table-format=-1.3,table-space-text-post=***]@{}}}
    \toprule
    \multirow{2}{*}{} & \multicolumn{3}{c|}{\textbf{2005}} & \multicolumn{3}{c|}{\textbf{2006}}  \\ \cmidrule(l){2-7} 
     & Q1 & Q2 & Q3 & Q1 & Q2 & Q3  \\ \midrule
    Price   & 0.99 & 5.45 & -0.13 & 0.11* & 0.77 & 5.11   \\ 
    Profit  &-0.01*** & -2.09 & 0.01 & -0.22** & 9.33 & -3.01   \\ 
    \bottomrule
    \end{tabular}
    \end{table*}
  • 1
    Can you give a WME, with all the packages you use ? – Jérôme Dequeker May 12 '16 at 6:36
  • Replace table-space-text-post=*** by table-space-text-post=\*\*\* – Jérôme Dequeker May 12 '16 at 6:40
  • @JérômeDequeker * isn't a special character that needs escaping, so that doesn't help. – Torbjørn T. May 12 '16 at 6:44
  • Off-topic: \multirow{2}{*}{} may be omitted entirely. You should also remove the pair of curly braces around S[...]@{}. – Mico May 12 '16 at 6:45
  • 1
    @JérômeDequeker Oops, that's actually a mistake on my part. You don't have to brace them. That was something I tried just to check if it mattered (which I didn't think it will), and forgot to change back. – Torbjørn T. May 12 '16 at 7:34
6

I looks like the fact that you've wrapped S[..] in braces throws the parser off. At least, removing the {} removes the error.

Note that vertical rules and booktabs don't go well together, so below I've removed the rules. I also used an S column for all the six last columns, that have numbers, and some other small changes.

enter image description here

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
  \begin{table*}[htb]
    \centering  
    \begin{tabular}{@{}l *{6}{S[table-format=-1.2,table-space-text-post=***]}@{}}
    \toprule
    & \multicolumn{3}{c}{\textbf{2005}} & \multicolumn{3}{c}{\textbf{2006}}  \\ \cmidrule(lr){2-4}\cmidrule(lr){5-7}
     & {Q1} & {Q2} & {Q3} & {Q1} & {Q2} & {Q3}  \\ \midrule
    Price   & 0.99 & 5.45 & -0.13 & 0.11* & 0.77 & 5.11   \\ 
    Profit  &-0.01*** & -2.09 & 0.01 & -0.22** & 9.33 & -3.01   \\ 
    \bottomrule
    \end{tabular}
    \end{table*}
\end{document}
  • @Mico Excellent point, I somehow failed to count the decimals ... Thanks! – Torbjørn T. May 12 '16 at 6:52
  • Thanks @TorbjørnT. that fixed the issue. Also, thanks for the other information. – Co Koder May 12 '16 at 7:03

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.