根据小数点对齐数字

根据小数点对齐数字

我有下表:

\documentclass{article}
\usepackage{booktabs}
\begin{document}    
\begin{table}
\centering
\begin{tabular}{ lcccccccc } 
\toprule
\multicolumn{5}{c}{\textbf{Training time per fold}}  \\ 
\toprule
\textbf{Average per fold}     & 1462.20 & 1482.31 & 1487.15 & 1496.49    \\[2pt] \hline
\textbf{Stddev per fold}      & 35.13   & 28.09   &  30.10  &  31.30   \\[2pt] \hline
\textbf{Average per sequence} & 365.55  & 370.58  &  371.79 &  374.12   \\[2pt] 
\midrule
\multicolumn{5}{c}{\textbf{Time for classification per fold}} \\ 
\midrule
\textbf{Average per fold}     & 1092.39 & 1101.13  & 1102.03 & 1080.47 \\[2pt] \hline
\textbf{Stddev per fold}      &  53.17  & 43.73    & 46.43   & 45.66   \\[2pt] \hline
\textbf{Average per sequence} & 273.10  & 275.28   & 275.51  & 270.12  \\[2pt] 
\bottomrule
\end{tabular}
\end{table}
\end{document}

我想根据小数位置对齐所有数字,这意味着所有点都应该对齐。

答案1

siunitx这是使用和的解决方案booktabs。不要使用太多规则。

\documentclass{article} 
\usepackage[utf8]{inputenc}
\usepackage{booktabs, array}
\usepackage{siunitx} 

\begin{document}

\begin{table}
\centering 
    \begin{tabular}{ l*{4}{S[table-format=4.2, table-number-alignment=center]}}
         \toprule 
         \multicolumn{5}{c}{\textbf{Training time per fold}} \\
         \cmidrule[\lightrulewidth](lr){1-5}
         \textbf{Average per fold} & 1462.20 & 1482.31 & 1487.15 & 1496.49 \\ 
         %\hline%
         \textbf{Stddev per fold} & 35.13 & 28.09 & 30.10 & 31.30 \\[2pt]
         %\hline%
         \textbf{Average per sequence} & 365.55 & 370.58 & 371.79 & 374.12 \\ 
         \midrule[\heavyrulewidth]
         \multicolumn{5}{c}{\textbf{Time for classification per fold}} \\ 
         \cmidrule[\lightrulewidth](lr){1-5}
         \textbf{Average per fold} & 1092.39 & 1101.13 & 1102.03 & 1080.47 \\ 
         %\hline %
         \textbf{Stddev per fold} & 53.17 & 43.73 & 46.43 & 45.66 \\ 
        % \hline %
         \textbf{Average per sequence} & 273.10 & 275.28 & 275.51 & 270.12 \\ 
     \bottomrule \end{tabular}
  \end{table}

\end{document} 

在此处输入图片描述

相关内容