![Chemfig - 如何在分子中形成不同颜色的键](https://linux22.com/image/440771/Chemfig%20-%20%E5%A6%82%E4%BD%95%E5%9C%A8%E5%88%86%E5%AD%90%E4%B8%AD%E5%BD%A2%E6%88%90%E4%B8%8D%E5%90%8C%E9%A2%9C%E8%89%B2%E7%9A%84%E9%94%AE.png)
我想画一个与水分子形成氢键的乙醇分子。
我希望它们之间的连接是一条虚线,红色,线,但所有其他的连接都是正常的,但我不知道该怎么做。
我的代码(到目前为止)是:
\documentclass{article}
\usepackage{chemfig}
\begin{document}
\begin{center}
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O^{\delta^{-}}H^{\delta^{+}}--O^{\delta^{-}}(-H^{\delta^{+}})(-[6]H^{\delta^{+}})}
\end{center}
\end{document}
答案1
稍微复杂一点的方法
\documentclass{article}
\usepackage{chemfig}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{center}
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-\charge{20:4pt=$^{\delta^{-}}$}{O}-[,0.5,,,draw=none]\charge{20:4pt=$^{\delta^{+}}$}{H}-[,1.5,,,draw=none,
postaction={decorate},
decoration={
markings,
mark = at position 0.22 with {\fill[red] circle[radius=1pt];},
mark = at position 0.5 with {\fill[red] circle[radius=1pt];},
mark = at position 1-0.22 with {\fill[red] circle[radius=1pt];}
}
]\charge{20:4pt=$^{\delta^{-}}$}{O}(-[6]\charge{20:4pt=$^{\delta^{-}}$}{H})-\charge{20:4pt=$^{\delta^{+}}$}{H}}
\end{center}
\end{document}
答案2
\documentclass{article}
\usepackage{chemfig}
\makeatletter
\tikzset{
dot diameter/.store in=\dot@diameter,
dot diameter=1pt,
dot spacing/.store in=\dot@spacing,
dot spacing=5.5pt,
dots/.style={
line width=\dot@diameter,
line cap=round,
dash pattern=on 0pt off \dot@spacing
}
}
\makeatother
\begin{document}
\begin{center}
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O^{\delta^{-}}H^{\delta^{+}}-[,2,,,thick, dotted, red]\charge{20:4pt=$^{\delta^{-}}$}{O}(-[6]\charge{20:4pt=$^{\delta^{-}}$}{H})-\charge{20:4pt=$^{\delta^{+}}$}{H}}
\end{center}
\begin{center}
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O^{\delta^{-}}H^{\delta^{+}}-[,2,,,dots, red]\charge{20:4pt=$^{\delta^{-}}$}{O}(-[6]\charge{20:4pt=$^{\delta^{-}}$}{H})-\charge{20:4pt=$^{\delta^{+}}$}{H}}
\end{center}
\end{document}