Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to fill the background of some functional groups or atoms including bonds to emphasize them. For instance, to emphasize carbonyl group in a keton, fill the background of C=O like:

enter image description here

I'm using chemfig to draw chemistry equations, and I have a workaround which cover with overlay(chemmove):

\chemfig{R|_1-@{kc}C(=[:90]O)-R|_2}
\chemmove{
    \node[fill=purple!20,anchor=text,inner sep=0.1em]
        at (kc.text) {\chemfig{C(=[:90]O)}};
}

However, I need simpler and smarter way since, in this way, I have to write the same code twice(which could be very long if the atoms and bonds are long and complicated) and it does not work with wrong anchoring from time to time.

share|improve this question
    
Welcome to TeX.sx! –  cgnieder Jul 14 '13 at 12:47
    
@cgnieder Thanks! –  xylosper Jul 14 '13 at 15:05

1 Answer 1

up vote 4 down vote accepted

You could mark two nodes with the @{<name>} syntax and then draw a rectangle with fill opacity=.2 (or whatever suits you best):

\documentclass{article}
\usepackage{chemfig,tikz}
\begin{document}
\chemfig{R_1-@{C}C(=[:90]@{O}O)-R_2}
\chemmove{
  \draw[
    fill=purple,
    draw=purple,
    fill opacity=.2,
    rounded corners=2pt
  ]
    ([xshift=-3pt,yshift=-1pt]C.south west)
    rectangle
    ([xshift=3pt,yshift=3pt]O.north east) ;
}
\end{document}

result

share|improve this answer
    
This looks nice but it's another workaround, isn't it? Because the filled rectangle is laid over C=O, the fill opacity value shoulde be small otherwise it will paint out the below drawings. Although I think this is simple and very helpful, I want to wait for more general solution which does not cover the drawings. Thank you! –  xylosper Jul 14 '13 at 15:04
    
“[...] it's another workaround, isn't it? ” - Well, that may be, but at least it saves you the trouble of typing the concerned molecule part twice :) –  cgnieder Jul 14 '13 at 21:48
    
Yes, I agree with you. It is definitely better and I couldn't find any other solution. Thanks. –  xylosper Jul 15 '13 at 1:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.