我想让变量(在 Latex3 中定义)在表格中对齐,并带有小数点。当然,不用使用“反复试验”的额外空格“,” 。有这种可能吗?非常感谢。
\documentclass{article}
\usepackage{xparse}
\usepackage[version=4]{mhchem}
\usepackage{siunitx,booktabs}
%
\ExplSyntaxOn
\NewDocumentCommand{\calcnumd}{o m}
{\IfValueTF{#1}
{\num[round-mode = figures, round-precision = #1, round-integer-to-decimal]{\fp_to_decimal:n{#2}}}
{\num{\fp_to_decimal:n{#2}}}
}
% data
\fp_set:Nn \dhfbiox {33.18}
\fp_set:Nn \dhftetrox {9.16}
\fp_set:Nn \dgfbiox {51.31}
\fp_set:Nn \dgftetrox {97.89}
\fp_set:Nn \cpbiox {37.20}
\fp_set:Nn \cptetrox {77.28}
% calculations
%
\ExplSyntaxOff
%
\begin{document}
\begin{center}
\begin{tabular}{l|ccc}
& $\Delta_f H^{\ominus}$ & $\Delta_f G^{\ominus}$ & $C_P$ \\
& \si{\kilo\joule\per\mole} & \si{\kilo\joule\per\mole} & \si{\joule\per\kelvin\per\mole} \\
\midrule
\ce{NO2} & \calcnumd{\dhfbiox} & \calcnumd{\dgfbiox} & \calcnumd[4]{\cpbiox} \\
\ce{N2O4} & \,\,\,\calcnumd{\dhftetrox} & \calcnumd{\dgftetrox} & \calcnumd{\cptetrox} \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
答案1
使用S
由 定义的列类型siunitx
。
\documentclass{article}
\usepackage[version=4]{mhchem}
\usepackage{siunitx,booktabs}
\begin{document}
\begin{center}
\begin{tabular}{l|SSS}
& $\Delta_f H^{\ominus}$ & $\Delta_f G^{\ominus}$ & $C_P$ \\
& \si{\kilo\joule\per\mole} & \si{\kilo\joule\per\mole} & \si{\joule\per\kelvin\per\mole} \\
\midrule
\ce{NO2} & 33.18 & 51.31 & 37.20 \\
\ce{N2O4} & 9.16 & 97.89 & 77.28 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}