我正在尝试将 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}
答案1
chemfig
arrival 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}