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.

P.S. This question is specific to Latex3 and should not be assimilated to a Latex2e well known method to align numbers in tables.

\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
    You shouldn't ask two identical questions. If your previous question was closed as a duplicate, please edit it explaining why it is not a duplicate (possibly including how the solutions to the linked duplicate don't work for you), and it should be reopened – Phelype Oleinik Sep 19 '20 at 14:05
  • The P.S. explains why the question is not a duplicate and the answer is therefore not valid. – Alby Stalks Sep 19 '20 at 14:08
  • 1
    The P.S. should be an edit to your previous question, not added to a new, otherwise identical question. Besides, siunitx is written using expl3, so I don't understand what other “LaTeX3” you want, other than the \fp_set:Nn you used... – Phelype Oleinik Sep 19 '20 at 14:14
  • In the table I want to use the variable directly, for example \dhfbiox and NOT retype the number 33.18. – Alby Stalks Sep 19 '20 at 14:19
  • So edit your old question and explain that – Phelype Oleinik Sep 19 '20 at 14:22
  • 1
    There isn't such a thing as latex3 outside latex2e, expl3 is now a part of latex2e. So use siunitx to align your numbers. – Ulrike Fischer Sep 19 '20 at 14:37
  • Using, for example, \calcnumd[5]{\dhfbiox} with S-column gives errors. Without the optional number of digits, it works but then there is the problem of trailing zeros. – Alby Stalks Sep 19 '20 at 16:28
  • The "duplicate" was my first question. Erroneously (from my point of view) it was closed, so I repeated the question in more detail. – Alby Stalks Sep 19 '20 at 19:42
  • you could (should) have edited the question to get it re-opened, although it doesn't matter but this is still a duplicate of the one that was referenced before. You can use siunitx to align numbers especially as you are already using that package. Your PS about latex3 can't really be answered, I have no idea what you mean by that, especially as siunitx is one of the main examples of an expl3 package. – David Carlisle Sep 19 '20 at 20:10
  • \calcnumd is a robust command, siunitx has no chance to expand it to a number and to align it (and no other command would have a chance either). – Ulrike Fischer Sep 19 '20 at 20:12
  • you can use an S column, there is no need to use \calcnum in each cell – David Carlisle Sep 19 '20 at 20:14

1 Answers1

0

enter image description here

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

David Carlisle
  • 757,742
  • This solution brings me back to the beginning: how to avoid removing the trailing zero in the number \cpbiox (37.20 and not 37.2)? – Alby Stalks Sep 19 '20 at 21:23
  • @AlbyStalks you can use whatever siunitx formatting options you want on S replace S by S[....] (you don't mention any such requirement in thsi question by the way) – David Carlisle Sep 19 '20 at 21:27
  • Ok! I apologize for not having been able to explain the problem correctly. The errors given by \calcnumd with the number of digits specified, confused me. – Alby Stalks Sep 20 '20 at 07:18