1

I would like to have the variables (defined in Latex3) aligned in a table with the decimal point. Of course, without using the "trial and error" extra space ",". Is there any possibility? Thank you very much.

\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}
0

1 Answer 1

2

Use S column type which is defined by 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}

enter image description here

1
  • This is not the solution I'm searching. It was the "starting point" some times ago. BTW, using the optional number of digits, i.e. \calcnumd[4]{\cpbiox} with the S columns gave errors. Sep 18, 2020 at 15:27

Not the answer you're looking for? Browse other questions tagged .