对齐表格中的小数点

对齐表格中的小数点

我想将表格中第二列和第三列的数值与小数点对齐。有人能帮我吗?

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{table}[htbp]
\centering
\begin{tabular}{p{2cm} *{2}{C{2.5cm}} C{2cm}}
   \toprule
     \multicolumn{1}{c}{ } &
     \multicolumn{1}{c}{sub-problem 1} &
     \multicolumn{1}{c}{sub-problem 2}\\
     \cmidrule(lr){2-2} \cmidrule(lr){3-3} 
     \multicolumn{1}{l}{$X=R/T$}&  \multicolumn{1}{c}{$F_{TH}^{opt}$} & \multicolumn{1}{c}{$F_{TH}^{W_{c}^{opt}}$} & \multicolumn{1}{c}{Error ($\%$)} \\              
   \midrule
   $0.33$  & 0.054 & 0.1209 & $6.7$ \\
   $0.6$   & 0.0102 & 0.0373 & $2.7$ \\
   $0.866$ & 0.0032 & 0.0179 & $1.47$ \\
   $1$     & 0.002 & 0.002 & $0$ \\
   $1.2$   & 0.0023 & 0.0061 & $0.38$ \\
   $2$     & 0.0036 & 0.0827 & $7.9$ \\
   \bottomrule
\end{tabular}
\caption{ }
\label{ }
\end{table}

答案1

有了siunitx,一切就简单了:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{booktabs, caption}
\captionsetup{labelfont = sc}
\usepackage{siunitx}

\begin{document}

\begin{table}[htbp]
  \centering\sisetup{table-format=1.4, table-number-alignment=center}
  \begin{tabular}{S[table-format=1.3] *{2}{S}S[table-format=1.2] }
    \toprule & {sub-problem 1} &{sub-problem 2}\\
    \cmidrule(lr){2-2} \cmidrule(lr){3-3}
    {$X=R/T$} & {$F_{TH}^\textrm{opt}$} & {$F_{TH}^{W_{c}^\textrm{opt}}$} & {Error ($\%$)} \\
    \midrule
    0.33 & 0.054 & 0.1209 & 6.7 \\
    0.6 & 0.0102 & 0.0373 & 2.7 \\
    0.866 & 0.0032 & 0.0179 & 1.47 \\
    1 & 0.002 & 0.002 & 0 \\
    1.2 & 0.0023 & 0.0061 & 0.38 \\
    2 & 0.0036 & 0.0827 & 7.9 \\
    \bottomrule
  \end{tabular}
  \caption{ }
  \label{ }
\end{table}

\end{document} 

在此处输入图片描述

相关内容