当其中一行包含公式中的键时,表格行之间会出现不必要的跳行\ch
,例如
\documentclass{article}
\usepackage{chemformula}
\lineskiplimit=-1em
\begin{document}
\begin{minipage}{0.2\textwidth}
\begin{tabular}{r}
\hline
\ch{H2O} \\
\ch{CH3OCH3} \\
\ch{H3PO4} \\
\hline
\end{tabular}
\end{minipage}
%
\begin{minipage}{0.2\textwidth}
\begin{tabular}{l}
\hline
\ch{H2O} \\
\ch{CH3-O-CH3} \\
\ch{H3PO4} \\
\hline
\end{tabular}
\end{minipage}
\end{document}
左侧表格中第一行与第二行之间的间隔较大,且不受 的影响\lineskiplimit
。相关差异是\ch{CH3-O-CH3}
vs. \ch{CH3OCH3}
。
有没有简单的方法可以解决这个问题?
答案1
chemformula
4.15i 版本中已修复此问题:
\documentclass{article}
\usepackage{chemformula}[2020/02/01]% v4.15i or newer
\begin{document}
\begin{minipage}{0.2\textwidth}
\begin{tabular}{r}
\hline
\ch{H2O} \\
\ch{CH3OCH3} \\
\ch{H3PO4} \\
\hline
\end{tabular}
\end{minipage}
\begin{minipage}{0.2\textwidth}
\begin{tabular}{l}
\hline
\ch{H2O} \\
\ch{CH3-O-CH3} \\
\ch{H3PO4} \\
\hline
\end{tabular}
\end{minipage}
\end{document}
在旧版本中,序言中的以下代码应该执行:
\ExplSyntaxOn
\cs_set_protected:Npn \chemformula_bond:n #1
{
\chemformula_skip_nobreak:N \l__chemformula_bond_space_dim
\hbox_set:Nn \l__chemformula_tmpa_box {K}
\dim_set:Nn \l__chemformula_tmpa_dim { \box_ht:N \l__chemformula_tmpa_box }
\chemformula_tikz:nn
{
inner~sep = 0pt ,
outer~sep = 0pt ,
text~height = \l__chemformula_tmpa_dim ,
baseline = (chemformula-bond-ground.base)
}
{
\coordinate (chemformula-bond-ground) at (0pt,0pt) ;
\draw (chemformula-bond-ground) ++ (0pt,.5\l__chemformula_tmpa_dim)
coordinate (chemformula-bond-start) ;
\draw (chemformula-bond-start) ++(\l__chemformula_bond_dim ,0pt)
coordinate (chemformula-bond-end) ;
\tl_if_blank:nTF {#1}
{ \__chemformula_bond_draw:n {single} }
{ \__chemformula_bond_draw:n {#1} }
}
\chemformula_skip_nobreak_penalty:NV
\l__chemformula_bond_space_dim
\l__chemformula_bond_penalty_tl
}
\ExplSyntaxOff
备注:行中\hbox_set:Nn \l__chemformula_tmpa_box {K}
K
不需要K
。任何没有降部的大写字母都应如此,键的位置差异最小。
(自我提醒:可能应该将键放在数学轴上......)
答案2
手动修复:您可以假装\ch{CH3-O-CH3
使用的高度为零\raisebox{0pt}[0pt]{\ch{CH3-O-CH3}}
,或者假装它具有与以下相同的高度\ch{CH3OCH3}
(此处:\heightof
从calc
包中使用):
\documentclass{article}
\usepackage{chemformula}
\usepackage{calc}
\begin{document}
\begin{tabular}{r}
\hline
\ch{H2O} \\
\ch{CH3OCH3} \\
\ch{H3PO4} \\
\hline
\end{tabular}%
%
\qquad
%
\begin{tabular}{l}
\hline
\ch{H2O} \\
\raisebox{0pt}[\heightof{\ch{CH3OCH3}}]{\ch{CH3-O-CH3}} \\
\ch{H3PO4} \\
\hline
\end{tabular}
\end{document}
当然,您可以使用该booktabs
包获得更好的规则,但这与问题无关:
\documentclass{article}
\usepackage{chemformula}
\usepackage{booktabs}
\usepackage{calc}
\begin{document}
\begin{tabular}{r}
\toprule
\ch{H2O} \\
\ch{CH3OCH3} \\
\ch{H3PO4} \\
\bottomrule
\end{tabular}%
%
\qquad
%
\begin{tabular}{l}
\toprule
\ch{H2O} \\
\raisebox{0pt}[\heightof{\ch{CH3OCH3}}]{\ch{CH3-O-CH3}} \\
\ch{H3PO4} \\
\bottomrule
\end{tabular}
\end{document}