在表格中定义 mhchem 反应而不显示空格

在表格中定义 mhchem 反应而不显示空格

我使用 mhchem 进行反应格式化,并使用 Martin Hensel 的建议进行反应标记和编号(来自mhchem 文档)。如下例所示,表格中列出/定义了几种反应。默认情况下,我在方程式的上方和下方会得到很多额外的空白(即非常宽的表格行,如下例中的最后一行所示)。我能够做到这一点而没有额外空白的唯一方法是将定义括在 中\multicolumn{1}{l}{}。我尝试通过表格环境中的 eg 更改 displayskip 参数\setlength\abovedisplayskip{0pt},但没有成功。

\multicolumn{1}{l}{}给了我一个看起来不错的表格(我希望等式左对齐,R1、R2 等右对齐),但有以下编译器错误:

  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

有没有更好的方法可以做到这一点并且不会产生编译错误?

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

格式化乳胶输出

答案1

我建议使用一个\tablereaction宏来避免猜测宽度。它跨越两列,因此在第二行你需要使用&&

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

在此处输入图片描述

具有特征的实现xparse

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

我添加了一些\reaction命令来测试;您会看到引用是正确的。

在此处输入图片描述

相关内容