分子角问题(Tikz/Chemfig)

分子角问题(Tikz/Chemfig)

基于答案埃里克,我能够制作一个带有键长和键角标签的分子图。但出现了一个困难。最后一个角度应该在两个氧键之间 - 但它就像从氧键到氢键再到氧双键一样。

结果应该是一个带有角度标签的分子,其中所有角度都位于该标签中。实际上,只是最后一个角度的位置不正确(我在代码的末尾标记了错误的键合)。这是代码。

\documentclass[border=2pt]{standalone}
\usepackage{chemfig}
\usepackage{siunitx}

\newcommand\namebond[5][-1pt]{\chemmove{\path(#2)--(#3)node[midway,#4,yshift=#1,black!60]{#5};}}
\newcommand\arcbetweennodes[3]{%
\pgfmathanglebetweenpoints{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}% 
\let#3\pgfmathresult}

\newcommand\arclabel[6][red,-stealth,shorten <=1pt,shorten >=1pt]{%
\chemmove{%
\arcbetweennodes{#4}{#3}\anglestart \arcbetweennodes{#4}{#5}\angleend \draw[#1]([shift=(\anglestart:#2)]#4)arc(\anglestart:\angleend:#2); \pgfmathparse{(\anglestart+\angleend)/2}\let\anglestart\pgfmathresult \node[shift=(\anglestart:#2+1pt)#4,anchor=\anglestart+180,inner sep=0pt,
outer sep=0pt]at(#4){#6};}}

\begin{document}
\setatomsep{2cm}
\chemfig{@{hl}H-[:34]@{c}C(=[:+90]O@{ot})-[::+-56]@{ob}O-[::55]@{hr}H}
\namebond{hl}{c}{above,sloped}{$a$}
\namebond{c}{ot}{right}{$b$}
\namebond{c}{ob}{above,sloped}{$c$}
\namebond{ob}{hr}{above,sloped}{$d$}
\arclabel{0.5cm}{hl}{c}{ob}{\footnotesize \SI{112}{\degree}}
\arclabel{0.5cm}{c}{ob}{hr}{\footnotesize \SI{110}{\degree}}
\arclabel{0.5cm}{hl}{c}{ot}{\footnotesize \SI{130}{\degree}}
%The next one is the problem
\arclabel{0.5cm}{ot}{c}{ob}{\footnotesize \SI{33}{\degree}}
\end{document}

现在看起来是这样的... 角度错误的图片。

希望您明白我的意思?谨致问候,提前谢谢您!

答案1

解决方法如下:

\documentclass{article}
\usepackage{chemfig}
\usepackage{siunitx}

\newcommand\namebond[5][-1pt]{\chemmove{\path(#2)--(#3)node[midway,#4,yshift=#1,black!60]{#5};}}
\newcommand\arcbetweennodes[3]{%
    \pgfmathanglebetweenpoints{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}%
    \let#3\pgfmathresult}

\newcommand\arclabel[6][red,-stealth,shorten <=1pt,shorten >=1pt]{%
    \chemmove{%
        \arcbetweennodes{#4}{#3}\anglestart
        \arcbetweennodes{#4}{#5}\angleend
        \ifdim\anglestart pt>\angleend pt \pgfmathsetmacro\anglestart{\anglestart-360}\fi
        \draw[#1]([shift=(\anglestart:#2)]#4)arc[start angle=\anglestart,end angle=\angleend,radius=#2];%
        \pgfmathsetmacro\anglestart{(\anglestart+\angleend)/2}%
        \node[shift=(\anglestart:#2+1pt)#4,anchor=\anglestart+180,inner sep=0pt,outer sep=0pt]at(#4){#6};%
    }%
}

\begin{document}
\setatomsep{2cm}
\chemfig{@{hl}H-[:34]@{c}C(=[:90]O@{ot})-[::-56]@{ob}O-[::55]@{hr}H}
\namebond{hl}{c}{above,sloped}{$a$}
\namebond{c}{ot}{right}{$b$}
\namebond{c}{ob}{above,sloped}{$c$}
\namebond{ob}{hr}{above,sloped}{$d$}
\arclabel{0.5cm}{hl}{c}{ob}{\footnotesize \SI{112}\degree}
\arclabel{0.5cm}{hr}{ob}{c}{\footnotesize \SI{110}\degree}
\arclabel{0.5cm}{ot}{c}{hl}{\footnotesize \SI{130}\degree}
\arclabel{0.5cm}{ob}{c}{ot}{\footnotesize \SI{33}\degree}
\end{document}

在此处输入图片描述

相关内容