我刚开始使用chemfig
,我需要聚合物的配方。一切都很完美,除了我有一个额外的支架,正如您从图片中看到的那样。
我的代码如下(第一部分只是从chemfig
包的文档中复制而来):
\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$}}
\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim width0pt\right.$};}}
\setpolymerdelim[]
\chemfig{[:18]-[@{open,.5}] *5((-)- S - (-[@{close,.5}] )= (-#(,6pt)(CH_2{(}CH_2{)}_4 CH_3)) - =)}
\makebraces[45pt,10pt]{n}{open}{close}
我怎样才能去掉那个多余的括号?
答案1
下面的代码片段是宏定义的最后一行用于创建括号的一部分,但是是多余的:
\left\delimleft\vrule height\delimhalfdim depth\delimhalfdim width0pt\right.
删除它可以解决您的问题。
另外,请检查您使用的手册是否为最新版本ChemFig
。此错误行不在 2015 年 12 月的手册 1.2d 版本中。也许这只是一个复制/粘贴错误?
这是 MWE,后面是聚合物的绘图。
\documentclass[border=5pt,crop=true]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{chemfig}
\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}
\chemfig{[:18]-[@{open,.5}] *5((-)- S - (-[@{close,.5}] )= (-#(,6pt)(CH_2{(}CH_2{)}_4 CH_3)) - =)}
\makebraces[45pt,10pt]{n}{open}{close}
\end{document}