如何对齐 expl3 浮点变量

如何对齐 expl3 浮点变量

我想让变量(在 Latex3 中定义)在表格中对齐,并带有小数点。当然,不用使用“反复试验”的额外空格“,” 。有这种​​可能吗?非常感谢。

PS:这个问题是特定于 Latex3 的,不应该被同化为 Latex2e 众所周知的在表格中对齐数字的方法。

\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

在此处输入图片描述

\documentclass{article}
\usepackage{xparse,xfp}
\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|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} & \fpeval{\dhfbiox} & \fpeval\dgfbiox & \fpeval\cpbiox \\
\ce{N2O4} & \fpeval\dhftetrox & \fpeval\dgftetrox & \fpeval\cptetrox \\
\bottomrule
\end{tabular}
\end{center}

\end{document}

相关内容