在表格中将数字按小数点对齐

在表格中将数字按小数点对齐

我正在尝试在表格中按十进制对齐数字。我在这里找到了一些信息:对齐表格中的小数点。但是,当我将该代码应用到我的表中时,它会出现错误:

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

我不明白为什么会出现上述错误,有人能帮帮我吗?

这是我的乳胶代码:

  \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

看起来,您用S[..]括号括起来的事实会使解析器出错。至少,删除{}可以消除错误。

请注意,垂直规则和booktabs不太协调,因此下面我删除了这些规则。我还S为所有最后六列使用了一列,其中包含数字,并进行了一些其他小改动。

在此处输入图片描述

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

相关内容