如何在 chemfig 中将文本 H 写入 O 的左边?

如何在 chemfig 中将文本 H 写入 O 的左边?

我正在尝试将 H 放在 O 的左边,正确的语法是什么?这是我的 MWE

 \documentclass[a4paper]{article}
 \usepackage{chemfig}

 %%% Polymer symbol
 \newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}
 \def\makebraces[#1,#2]#3#4#5{%
   \edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
   \edef\delimvshift{\the\dimexpr(#1-#2)/2}%
   \chemmove{%
     \node[at=(#4),yshift=(\delimvshift)]
        {$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
        width0pt\right.$};%
     \node[at=(#5),yshift=(\delimvshift)]
        {$\left.\vrule height\delimhalfdim depth\delimhalfdim
        width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}
 \setpolymerdelim()



 \begin{document}

 \setpolymerdelim[]
 \setchemfig{atom sep=2em}
 \chemfig{[:30]-[@{left,0.65}]-[:-30](-[6]OH)-[@{right,0.75}:30]}
 \makebraces[15pt,35pt]{n}{left}{right}

 \end{document}

以下是上述 MWE 的输出 在此处输入图片描述

答案1

chemfigarrival atom提供了此功能。您可以在绘制键时的第四个可选参数中指定要将键连接到的原子,称为 ,如下所示:

...(-[6,,,2]HO)...

HO请注意,我也切换了的顺序,因此chemfig画出HO,但我们将到达原子改为第二个原子,它仍然是O

\documentclass[a4paper]{article}
\usepackage{chemfig}

%%% Polymer symbol
\newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}
\def\makebraces[#1,#2]#3#4#5{%
    \edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
    \edef\delimvshift{\the\dimexpr(#1-#2)/2}%
    \chemmove{%
        \node[at=(#4),yshift=(\delimvshift)]
        {$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
            width0pt\right.$};%
        \node[at=(#5),yshift=(\delimvshift)]
        {$\left.\vrule height\delimhalfdim depth\delimhalfdim
            width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}
\setpolymerdelim()



\begin{document}

    \setpolymerdelim[]
    \setchemfig{atom sep=2em}
    \chemfig{[:30]-[@{left,0.65}]-[:-30](-[6,,,2]HO)-[@{right,0.75}:30]}
    \makebraces[15pt,35pt]{n}{left}{right}

\end{document}

在此处输入图片描述

答案2

使用盒子的简单版本。

化学无花果

 \documentclass[a4paper]{article}
 \usepackage{chemfig}

 %%% Polymer symbol
 \newcommand\setpolymerdelim[2]{\def\delimleft{#1}\def\delimright{#2}}
 \def\makebraces[#1,#2]#3#4#5{%
   \edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
   \edef\delimvshift{\the\dimexpr(#1-#2)/2}%
   \chemmove{%
     \node[at=(#4),yshift=(\delimvshift)]
        {$\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim
        width0pt\right.$};%
     \node[at=(#5),yshift=(\delimvshift)]
        {$\left.\vrule height\delimhalfdim depth\delimhalfdim
        width0pt\right\delimright_{\rlap{$\scriptstyle#3$}}$};}}
 \setpolymerdelim()

\newsavebox{\leftofbox}
\newlength{\widthofbox}
\def\leftof#1#2{%
    \savebox{\leftofbox}{#2}%
    \setlength{\widthofbox}{\wd\leftofbox}%
    \hskip\widthofbox
    \llap{#1#2}%
}

 \begin{document}

 \setpolymerdelim[]
 \setchemfig{atom sep=2em}
 \chemfig{[:30]-[@{left,0.65}]-[:-30](-[6]\leftof{H}{O})-[@{right,0.75}:30]}
 \makebraces[15pt,35pt]{n}{left}{right}

 \end{document}

相关内容