我有以下代码:
\documentclass[12pt]{report}
\usepackage{chemfig}
%these for bonds in chemfig
\setdoublesep{0.35700 em} % 'Bond Spacing'
\setatomsep{1.78500 em} % 'Fixed Length'
\setbondoffset{0.18265 em} % 'Margin Width'
\newcommand{\bondwidth}{0.06642 em} % 'Line Width'
\setbondstyle{line width = \bondwidth}
%Drawing parentheses around polymers
\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{#3}}
$};
}%
}
%
%----------------------------end of preamble---------------------------------
%
\begin {document}
\setpolymerdelim() \chemfig{[:-30]*6((-C(-[:240]Cl
[@{op,.25}]
)(=[:120]O))=-=(-C(-[:300]OCH_2CH_2-O-[@{cl,.25}]H)(=[:60]O))-=-)} \makebraces(35pt,15pt){$\!\!{\rm n}$}{op}{cl}
\end {document}
这给了我这样的图像:
如果有人熟悉 中的括号chemfig
,请运行代码,看看能否回答我?我将不胜感激!
我能得到一些帮助来整理左括号的位置并去掉 Cl 后面的小框吗?
感谢您的回复,但需要澄清的是,我想实现以下目标
答案1
您输入了\chemfig{...Cl[@{op,.25}]...}
这意味着 »Cl« 原子有一个可选参数。但是,原子没有可选参数!这意味着chemfig
将方括号解释为原子,即对它们进行排版。这会导致您看到的“小盒子”。
该语法有两个合法的地方@{...}
:
- 使用语法“
@{<name>,<coeff>}
”将键上的零大小节点放置在相关键的可选参数的开头,如果有第一个可选参数,则后面不跟逗号。在这种情况下,节点采用名称“<name>
”,并且<coeff>
必须位于0
和之间1
,它确定节点在键上的位置。如果@{<name>}
使用“ ”,则默认<coeff>
设置为0.5
,这意味着节点位于键的中间位置;- 使用语法“
@{<name>}
”在相关原子之前紧接着查找原子上的节点。在这种情况下,节点具有与原子完全相同的占用空间,但可能为空,因此具有零维度。
这样\chemfig{...Cl[@{op,.25}]...}
您就有效地标记了结束方括号。
解决方法:在方括号前面加一个键\chemfig{...Cl-[@{op,.25}]...}
。
其余部分都很好(看起来像是从文档中复制的宏)。您只需使用和 的参数<coeff>
值即可。(#1,#2)
\makebraces
\documentclass[12pt]{report}
\usepackage{chemfig}
%these for bonds in chemfig
\setdoublesep{0.35700 em} % 'Bond Spacing'
\setatomsep{1.78500 em} % 'Fixed Length'
\setbondoffset{0.18265 em} % 'Margin Width'
\newcommand{\bondwidth}{0.06642 em} % 'Line Width'
\setbondstyle{line width = \bondwidth}
%Drawing parentheses around polymers
\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{#3}}
$};
}%
}
%
%----------------------------end of preamble---------------------------------
%
\begin {document}
\setpolymerdelim()
\chemfig{
[:-30]*6(
(-C
(-[@{op,.7}:225,2]Cl)
(=[:120]O)
)=-=(-C
(-[:300]OCH_2CH_2-O-[@{cl,.25}]H)
(=[:60]O)
)-=-
)
}
\makebraces(45pt,15pt){$\!\!{n}$}{op}{cl}
\end {document}
答案2
也许你想要的是这样的:
\documentclass[12pt]{report}
\usepackage{chemfig}
%these for bonds in chemfig
\setdoublesep{0.35700 em} % 'Bond Spacing'
\setatomsep{1.78500 em} % 'Fixed Length'
\setbondoffset{0.18265 em} % 'Margin Width'
\newcommand{\bondwidth}{0.06642 em} % 'Line Width'
\setbondstyle{line width = \bondwidth}
%Drawing parentheses around polymers
\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{#3}}
$};
}%
}
%
%----------------------------end of preamble---------------------------------
%
\begin {document}
\setpolymerdelim() \chemfig{[:-30]*6((-C(-[:240]Cl-[@{op,0.2},,,,draw=none]
)(=[:120]O))=-=(-C(-[:300]OCH_2CH_2-O-[@{cl,.25}]H)(=[:60]O))-=-)} \makebraces(45pt,15pt){$\!\!\textrm{n}$}{op}{cl}
\end {document}