如何將表格中的數字與單位對齊

如何將表格中的數字與單位對齊

如何將表格中的數字與單位對齊?我嘗試使用 siunitx 但它不起作用:

\begin{table}
    \centering
    \caption{Caption goes here.}
    \begin{tabular}[t]{lS}
        \toprule
        Substance   & Amounts \\ \midrule
        A           & 1 $mL$    \\
        B           & 100 $mg$  \\
        C           & 0.5 $mg$  \\
        D           & 82 $\mu L$   \\
        E           & 0.1 $g$   \\bottomrule
    \end{tabular}
\end{table}

如果有可能的話,我也會手動完成,因為我確實寫不需要很多表。先致謝

答案1

像這樣的東西嗎?

在此輸入影像描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{siunitx,booktabs,array}

\begin{document}
\begin{table}
    \centering
    \caption{Caption goes here.}
    \begin{tabular}[t]{ @{} 
                        l 
                        S[table-format=2.1] 
                        @{\,} 
                        s[table-unit-alignment=left]
                        @{} }
        \toprule
        Substance   & \multicolumn{2}{c@{}}{Amounts} \\ 
        \midrule
        A           & 1   & \milli\liter    \\
        B           & 100 & \milli\gram  \\
        C           & 0.5 & \milli\gram  \\
        D           & 82  & \micro\liter    \\
        E           & 0.1 & \gram   \\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}

相關內容