如何對齊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}

相關內容