I have a chemfig structure where I want to highlight certain positions by drawing a simple circle at the atom site. This works so far, but I would also like to have the new nodes on top of the structure. I have tried the solution given in https://tex.stackexchange.com/a/20426/12740, but it does not work..
MWE:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{chemfig}
\pgfdeclarelayer{front}
\pgfsetlayers{main,front}
\makeatletter
\pgfkeys{%
/tikz/on layer/.code={
\pgfonlayer{#1}\begingroup
\aftergroup\endpgfonlayer
\aftergroup\endgroup
},
/tikz/node on layer/.code={
\gdef\node@@on@layer{%
\setbox\tikz@tempbox=\hbox\bgroup\pgfonlayer{#1}\unhbox\tikz@tempbox\endpgfonlayer\egroup}
\aftergroup\node@on@layer
},
/tikz/end node on layer/.code={
\endpgfonlayer\endgroup\endgroup
}
}
\def\node@on@layer{\aftergroup\node@@on@layer}
\makeatother
\newcommand*\ca{%
\tikz\draw[fill,opacity=0.5,draw=none,color=red,on layer=front] circle (.1);%
}
\newcommand*\cb{%
\tikz\draw[fill,opacity=0.9,draw=none,color=blue,on layer=front] circle (.15);%
}
\begin{document}
\setatomsep{2em}
\setdoublesep{.3em}
\begin{tikzpicture}
\node {%
\chemfig[line width=1pt]{%
[:-60]O-(-[::60]*6((\cb)-(\ca)=(\ca)-(\cb)(-([:60]=O)-[:-60]O)=(\ca)-(\ca)=))=[:-120]O}%
};
\end{tikzpicture}
\end{document}
I suspect the problem is in the defition of \ca
and \cb
, because it uses an own \tikz
command, but I don't know how to solve this.