1

I am using mhchem for reaction formatting, and am also using Martin Hensel's suggestion for reaction labelling and numbering (from the mhchem documentation). Several reactions are listed/defined in a table, as in the example below. By default I then get lots of extra whitespace above and below the equation (i.e. very wide table rows as in the last row of the example below). The only way I was able to do this without the extra whitespace was by enclosing the definition in \multicolumn{1}{l}{}. I tried altering the displayskip parameters via e.g. \setlength\abovedisplayskip{0pt} within the table environment, but that did not work.

The \multicolumn{1}{l}{} gives me a table that looks ok (I would prefer the equation left aligned and R1, R2, etc. right aligned), but with the following compiler errors:

  1. LaTeX Error: Bad math environment delimiter.
  2. You can't use `\eqno' in restricted horizontal mode.
  3. Underfull \hbox (badness 10000) in alignment at lines 46--46

Is there a better way of doing this that doesn't give compile errors?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[version=4]{mhchem}
\usepackage{tabularx}

% R1, R2, etc counter
\makeatletter
\newcounter{reaction}
\renewcommand\thereaction{R\arabic{reaction}}
\newcommand\reactiontag%
{\refstepcounter{reaction}\tag{\thereaction}}
\newcommand\reaction@[2][]%
{\begin{equation}\ce{#2}%
\ifx\@empty#1\@empty\else\label{#1}\fi%
\reactiontag\end{equation}}
\newcommand\reaction@nonumber[1]%
{\begin{equation*}\ce{#1}\end{equation*}}
\newcommand\reaction%
{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother

\begin{document}

\newcolumntype{D}{>{\hsize=.45\hsize\centering\arraybackslash}X}
\newcolumntype{A}{>{\hsize=.7\hsize\centering\arraybackslash}X}
\newcolumntype{K}{>{\hsize=.25\hsize\centering\arraybackslash}X}
\newcolumntype{R}{>{\hsize=2.0\hsize\raggedright\arraybackslash}X}
\newcolumntype{S}{>{\hsize=1.2\hsize\raggedright\arraybackslash}X}
\setlength{\tabcolsep}{0pt}
\setlength{\extrarowheight}{5pt}
\begin{table}[bt]
\caption{Reactions with rate parameters updated in this work, including the modified Arrhenius rate rate parameters $k=A \, T^{\beta} \, e^{-E_a/RT}$ with units cm$^3$, mol, s, and K.  Rates for the low and high pressure limits are indicated with $k_0$ and $k_{\infty}$, respectively.}
\small 
\begin{tabularx}{1.0\linewidth}{R K A D D S}
    \hline
    \textbf{Reactions} & rate & $A$ & $\beta$ & $E_a$ &  \textbf{Source} \\
    \hline
    \multicolumn{1}{l}{\reaction[rxn:NH2+O=HNO+H]{NH2 + O <=> HNO + H \,}} & 
    $k$  & 1.50$\times$10$^{15}$ & -0.547 &  836.7 & Sumathi et al. \\
      & $k$  & 7.73$\times$10$^{13}$ & -0.277 &  646.4 & (Duplicate) \\
    \multicolumn{1}{l}{\reaction[rxn:NH2+NO=N2+H2O]{NH2 + NO <=> N2 + H2O \,}} & 
    $k$  & 2.60$\times$10$^{19}$ & -2.369 &  870.0 & Song et al. \\
    \multicolumn{1}{l}{\reaction[rxn:NH2+NO=NNH+OH]{NH2 + NO <=> NNH + OH \,}} & 
    $k$  & 4.30$\times$10$^{10}$ &  0.294 & -866.0 & Song et al. \\
    \reaction[rxn:N2H2=NNH+H]{N2H2 <=> NNH + H \,}  &
    $k_{\infty}$ & 6.30$\times$10$^{16}$ & 0 & 64000 & No multicolumn \\
    \hline
\end{tabularx}
\end{table}

\end{document}

Formatted latex output

2
  • 1
    One advice: each entry except the source column should be purely math, use $1.5\times10^{15}$ etc. Then your negative numbers will also be correct
    – daleif
    Commented Jun 6, 2022 at 20:25
  • @daleif - Thanks for the note. egreg's solution below also sorted out the number formatting issues. Commented Jun 8, 2022 at 1:29

1 Answer 1

0

I propose a \tablereaction macro that avoids having to guess widths. It spans two columns, so in the second row you need to use &&.

\documentclass{article}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{array}

% R1, R2, etc counter
\makeatletter
\newcounter{reaction}
\renewcommand\thereaction{R\arabic{reaction}}
\newcommand\reactiontag{\refstepcounter{reaction}\tag{\thereaction}}
\newcommand\reaction@[2][]{%
  \begin{equation}\ce{#2}%
  \if\relax\detokenize{#1}\relax\else\label{#1}\fi
  \reactiontag\end{equation}%
}
\newcommand\reaction@nonumber[1]{%
  \begin{equation*}\ce{#1}\end{equation*}%
}
\newcommand\reaction{%
  \@ifstar{\reaction@nonumber}{\reaction@}%
}
\newcommand{\tablereaction}[2][]{%
  \ce{#2} & 
  \if\relax\detokenize{#1}\relax\else\refstepcounter{reaction}\label{#1}\thetag{\thereaction}\fi
}
  
\makeatother

\begin{document}

\begin{table}[htbp]

\caption{Reactions with rate parameters updated in this work, 
  including the modified Arrhenius rate rate parameters 
  $k=A$ $T^{\beta}$ $e^{-E_a/RT}$ with units \unit{cm^3}, \unit{mol}, 
  \unit{s}, and \unit{K}.  Rates for the low and high pressure limits 
  are indicated with $k_0$ and $k_{\infty}$, respectively.}

\small 
\setlength{\tabcolsep}{0pt}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l % the reaction
  c % the reaction number
  c % rate
  S[table-format=1.2e2] % A
  S[table-format=-1.3] % beta
  S[table-format=-3.1] % E_a
  l % source
}
\toprule
\textbf{Reactions} &&
 rate & {$A$} & {$\beta$} & {$E_a$} &  \textbf{Source} \\
\midrule
\tablereaction[rxn:NH2+O=HNO+H]{NH2 + O <=> HNO + H \,} &
   $k$ & 1.50e15 & -0.547 &  836.7 & Sumathi et al. \\
&&
$k$ & 7.73e13 & -0.277 &  646.4 & (Duplicate) \\
\tablereaction[rxn:NH2+NO=N2+H2O]{NH2 + NO <=> N2 + H2O \,} &
$k$ & 2.60e19 & -2.369 &  870.0 & Song et al. \\
\tablereaction[rxn:NH2+NO=NNH+OH]{NH2 + NO <=> NNH + OH \,} &
$k$ & 4.30e10 &  0.294 & -866.0 & Song et al. \\
\tablereaction[rxn:N2H2=NNH+H]{N2H2 <=> NNH + H \,} &
$k_{\infty}$  & 6.30e16 & 0 & {64000} & No multicolumn \\
\bottomrule
\end{tabular*}

\end{table}

\end{document}

enter image description here

An implementation with xparse features.

\documentclass{article}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{array}

% R1, R2, etc counter
\newcounter{reaction}
\renewcommand\thereaction{R\arabic{reaction}}
\newcommand\reactiontag{\refstepcounter{reaction}\tag{\thereaction}}

\NewDocumentCommand{\reaction}{som}{%
  \IfBooleanTF{#1}
    {\begin{equation*}\ce{#3}\end{equation*}}
    {%
     \begin{equation}
     \ce{#3}
     \IfValueT{#2}{\label{#2}}
     \reactiontag
     \end{equation}%
    }
}
\NewDocumentCommand{\tablereaction}{om}{%
  \ce{#2} & \IfValueT{#1}{\refstepcounter{reaction}\label{#1}\thetag{\thereaction}}%
}

\begin{document}

\begin{table}[htbp]

\caption{Reactions with rate parameters updated in this work, 
  including the modified Arrhenius rate rate parameters 
  $k=A$ $T^{\beta}$ $e^{-E_a/RT}$ with units \unit{cm^3}, \unit{mol}, 
  \unit{s}, and \unit{K}.  Rates for the low and high pressure limits 
  are indicated with $k_0$ and $k_{\infty}$, respectively.}

\small 
\setlength{\tabcolsep}{0pt}

\begin{tabular*}{\textwidth}{
  @{\extracolsep{\fill}}
  l % the reaction
  c % the reaction number
  c % rate
  S[table-format=1.2e2] % A
  S[table-format=-1.3] % beta
  S[table-format=-3.1] % E_a
  l % source
}
\toprule
\textbf{Reactions} &&
 rate & {$A$} & {$\beta$} & {$E_a$} &  \textbf{Source} \\
\midrule
\tablereaction[rxn:NH2+O=HNO+H]{NH2 + O <=> HNO + H \,} &
   $k$ & 1.50e15 & -0.547 &  836.7 & Sumathi et al. \\
&&
$k$ & 7.73e13 & -0.277 &  646.4 & (Duplicate) \\
\tablereaction[rxn:NH2+NO=N2+H2O]{NH2 + NO <=> N2 + H2O \,} &
$k$ & 2.60e19 & -2.369 &  870.0 & Song et al. \\
\tablereaction[rxn:NH2+NO=NNH+OH]{NH2 + NO <=> NNH + OH \,} &
$k$ & 4.30e10 &  0.294 & -866.0 & Song et al. \\
\tablereaction[rxn:N2H2=NNH+H]{N2H2 <=> NNH + H \,} &
$k_{\infty}$  & 6.30e16 & 0 & {64000} & No multicolumn \\
\bottomrule
\end{tabular*}

\end{table}

\reaction[test]{NH2 + NO <=> N2 + H2O}

\reaction{NH2 + NO <=> N2 + H2O}

\reaction*{NH2 + NO <=> N2 + H2O}

\ref{rxn:N2H2=NNH+H} and \ref{test}

\end{document}

I added some \reaction command to test; you see that the references are correct.

enter image description here

3
  • Sorry if this is a stupid question, since I'm no expert in LaTeX internals, but shouldn't there be a \makeatother somewhere after makeatletter?
    – Miyase
    Commented Jun 7, 2022 at 0:06
  • 1
    @Miyase No, I just forgot to remove \makeatletter
    – egreg
    Commented Jun 7, 2022 at 6:50
  • Thank you egreg, this is beautiful! It works great in the larger thesis document too. The \tablemacro is an elegant solution, and I love all the other bits you threw in there too: the number formatting, column width allocation, \toprule, \bottomrule, etc. I have several other tables that are going to get bits of this solution. Commented Jun 8, 2022 at 1:27

You must log in to answer this question.

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