# Molecular angle question (Tikz/Chemfig)

Based on the answer from erik, I am able to make a molecule diagram with labels for bond length and angles. But one difficulty appeared. The last angle should be between the two oxygen bondings - but it is like it goes from oxygen bonding over hydrogen bonding to oxygen dobbelbonding.

The result should be a molecule with angle labels where all the angles are. Actually it is just the last angle which is incorrect placed (I have marked the wrong bonding in the code, at the end of the code). Here is the code.

\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}


Here is how it looks now ...

Hopefully you know what I mean? Kind regards, and thank you in advance!

Here is a fix:

\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
\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}