4

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*}
6
  • 1
    Can you give a WME, with all the packages you use ? Commented May 12, 2016 at 6:36
  • Replace table-space-text-post=*** by table-space-text-post=\*\*\* Commented May 12, 2016 at 6:40
  • @JérômeDequeker * isn't a special character that needs escaping, so that doesn't help. Commented May 12, 2016 at 6:44
  • Off-topic: \multirow{2}{*}{} may be omitted entirely. You should also remove the pair of curly braces around S[...]@{}.
    – Mico
    Commented May 12, 2016 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. Commented May 12, 2016 at 7:34

1 Answer 1

7

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}
2
  • @Mico Excellent point, I somehow failed to count the decimals ... Thanks! Commented May 12, 2016 at 6:52
  • Thanks @TorbjørnT. that fixed the issue. Also, thanks for the other information.
    – Co Koder
    Commented May 12, 2016 at 7:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .