1

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.

1 Answer 1

1

As in this answer, you can draw over a chemfig by usin remember picture, overlay and naming coordinates with @{}.

\documentclass[border=7mm]{standalone}
\usepackage{chemfig}

\setatomsep{2em}
\setdoublesep{.3em}

\begin{document}
  \chemfig[remember picture, line width=1pt]{
    [:-60]O-(-[::60]*6(@{cb1}-@{ca1}=@{ca2}-@{cb2}(-([:60]=O)-[:-60]O)=@{ca3}-@{ca4}=))=[:-120]O
  }
  \begin{tikzpicture}[remember picture,overlay]
    \foreach \i in {1,...,4}
      \fill[opacity=0.5,color=red] (ca\i) circle (.1);
    \foreach \i in {1,2}
      \fill[opacity=0.5,color=blue] (cb\i) circle (.15);
  \end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .