我需要绘制一个通用的三嵌段共聚物,如本 MWE 和图中所示。我遇到的问题与分子的左侧和右侧有关。我希望它们仅以“(”和“)”结尾,不显示任何化学键。如果我保留“-”,则图像左侧的结果会带有化学键。如果我不包含它,则图像右侧的结果会带有“)”位置错误和一些垃圾字符。
我使用的是 Ubuntu 18.04 存档中的 chemfig 1.2e。这意味着我没有新版本软件包中引入的新功能。
谢谢 !
编辑:如果化学键变短的话还会有加分:)
\documentclass{article}
\usepackage{mwe}
\usepackage{chemfig}
\begin{document}
% Define a function to draw polymer structures
\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()
\chemfig{
-[@{opa,.75}]A-[@{cla,0.25}]
-[@{opb,.75}]B-[@{clb,0.25}]
-[@{opc,.75}]A\ [@{clc,0.25}]
}
\makebraces[5pt,5pt]{\!\!n_{i}}{opa}{cla}
\makebraces[5pt,5pt]{\!\!n_{i+1}}{opb}{clb}
\makebraces[5pt,5pt]{\!\!n_{i+2}}{opc}{clc}
\end{document}
答案1
欢迎!这里有一种方法:将这些键的不透明度设置为零。
\documentclass{article}
\usepackage{chemfig}
\begin{document}
% Define a function to draw polymer structures
\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()
\chemfig{
-[@{opa,.75},,,,opacity=0]A-[@{cla,0.25}]
-[@{opb,.75}]B-[@{clb,0.25}]
-[@{opc,.75}]A-[@{clc,0.25},,,,opacity=0]
}
\makebraces[5pt,5pt]{\!\!n_{i}}{opa}{cla}
\makebraces[5pt,5pt]{\!\!n_{i+1}}{opb}{clb}
\makebraces[5pt,5pt]{\!\!n_{i+2}}{opc}{clc}
\end{document}
请注意,可能还有更好的方法。然而这是A摆脱这些束缚的方法。