我有一个分子(在本例中为共聚物),我想通过给多个原子着色来突出显示单体。有没有比给每个原子和键分别着色更有效的方法?chemfig
语法可能相当冗长。
在 Google 上搜索“共聚物”,结果就是这个,这正是我想要实现的。
答案1
以下是为所有原子和键着色的方法:
\documentclass{article}
\usepackage{chemfig}
\begin{document}
\def\ZZ#1{\global\setbondstyle{thick,color=#1}\gdef\printatom##1{\color{#1}\ensuremath{\mathrm{##1}}}}
\def\paren#1{\rlap{\kern-.75em$\left(\vrule height1ex width0pt depth1ex\vrule height0pt width2.5em depth0pt\right)_{\!#1}$}}
\definesubmol\NN{-[,,,,draw=none]}
\definesubmol\Red{(!\NN\ZZ{red})}
\definesubmol\Green{(!\NN\ZZ{green!40!black})}
\definesubmol\Purple{(!\NN\ZZ{purple})}
\setatomsep{2em}\setbondstyle{thick}
\chemfig{[:30]!\Purple EtO-([,.75]=[2]S)-[:-30]S-[,,,,,black]!\Green(-[6,0.25]\paren n)
([,.75]-[2]O-(=[2]O)-[:-30])-[:-30,1.25]-[,1.25,,,,black]!\Red(-[6,0.25]\paren m)
([,.75]-[2]O-(=[2]O)-[:-30]tBu)-[:-30,1.25]-[,1.25]R}
\end{document}
答案2
这是一个简单的解决方案。它仍然需要一些调整,但思路和操作方法如下:
\documentclass{article}
\usepackage{chemfig}
\definecolor{col1}{RGB}{0,102,153}
\definecolor{col2}{RGB}{0,252,0}
\definecolor{col3}{RGB}{150,0,0}
\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{\tiny$#3$}}$};}}
\setpolymerdelim()
\begin{document}
\chemfig{
\textcolor{col1}{EtO}-[:30,,,,col1](=[:90,,,,col1]\textcolor{col1}{S})-[:-30,,,,col1]\textcolor{col1}{S}
-[@{left}:30](-[:90,,,,col2]\textcolor{col2}{O})-[:-30,,,,col2]-[@{right}:30,0.5]-[@{lleft}:30,0.5](-[:90,,,,col3]\textcolor{col3}{O})-[:-30,,,,col3]-[@{rright}:30,,,,col3]
}
{\color{col2}\makebraces[5pt,12pt]{m}{left}{right}}
{\color{col3}\makebraces[5pt,12pt]{n}{lleft}{rright}}
\end{document}
但是正如 cgnieder 提到的,您可能必须“手动”分别为每条键着色……