2

Why \colordoesn't work? I need to color the -OH oxydrilic function:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[
  a4paper,
  margin=15mm,
  bindingoffset=2mm,
  heightrounded,
]{geometry}

\usepackage{amsmath}
\usepackage{chemfig}
\usepackage[version=3]{mhchem}

\begin{document}
\schemestart
\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H)=C(-[:-60]H)-[:60]H}
\arrow(.-1--){->[\chemfig{H_2O}][\chemfig{H^+}]}[,1.5]
\chemfig{CH_3CH_2-[:-0]C(-[:90]{\color{red}OH})(-[:-90]H)-C(-[:-90]H)(-[:90]H)(-[:0]H)}
\schemestop
\end{document}

enter image description here

  • 1
    Have a look at the manual section 12.1 How to write a colored atom (p. 42 of the manual to v1.2e 2017-05-20) – clemens Jun 21 '17 at 20:10
  • Unrelated to the question, but: version 4 of mhchem was released about two years ago so \usepackage[version=4]{mhchem} seems more appropriate (unless you have an outdated TeX distribution…) – clemens Jun 21 '17 at 20:23
4

Using \textcolor seems to make it work.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[
  a4paper,
  margin=15mm,
  bindingoffset=2mm,
  heightrounded,
]{geometry}

\usepackage{amsmath}
\usepackage{chemfig}
\usepackage[version=3]{mhchem}
\usepackage{xcolor}
\begin{document}
\schemestart
\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H)=C(-[:-60]H)-[:60]H}
\arrow(.-1--){->[\chemfig{H_2O}][\chemfig{H^+}]}[,1.5]
\chemfig{CH_3CH_2-[:-0]C(-[:90]{\textcolor{red}{OH}})(-[:-90]H)-C(-[:-90]H)(-[:90]H)(-[:0]H)}
\schemestop
\end{document}

enter image description here

Apparently, using {\color{red}{OH}} also makes it work, just by bracing the "OH". Alternately, so does {{\color{red}OH}}, with the double brace.

However, as noted by the OP, it would be desirable to get just the oxygen linked to the bond, and so (after consulting the manual against my better judgment :^) I came up with this, in which I use a | to separate the atom specification, and apply color to each, respectively, as in {\color{red}{O}|\color{red}{H}}.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage[
  a4paper,
  margin=15mm,
  bindingoffset=2mm,
  heightrounded,
]{geometry}

\usepackage{amsmath}
\usepackage{chemfig}
\usepackage[version=3]{mhchem}
\usepackage{xcolor}
\begin{document}
\schemestart
\chemfig{CH_3CH_2-[:-60,,3]C(-[:-120]H)=C(-[:-60]H)-[:60]H}
\arrow(.-1--){->[\chemfig{H_2O}][\chemfig{H^+}]}[,1.5]
\chemfig{CH_3CH_2-[:-0]C(-[:90]{\color{red}{O}|\color{red}{H}})(-[:-90]H)-C(-[:-90]H)(-[:90]H)(-[:0]H)}
\schemestop
\end{document}

enter image description here

  • 2
    This behaviour is actually documented: section 12.1 How to write a colored atom p. 42 of the manual to v1.2e 2017-05-20 :) – clemens Jun 21 '17 at 20:10
  • I noticed that adding the color effect, it changes the bind offset. How would I do if I wanted carbon directly bound to oxygen? – Salvo Matteini Jun 21 '17 at 21:26
  • @SalvoMatteini I am not a user of the package to know the proper way, but this will, I think, give what you want: {\textcolor{red}{O\rlap{H}}} – Steven B. Segletes Jun 22 '17 at 0:10
  • 1
    @SalvoMatteini -{\color{red}O}|{\color{red}H} should work – clemens Jun 22 '17 at 7:00
  • @StevenB.Segletes using \llap/\rlap with chemfig should rarely if ever be necessary… – clemens Jun 22 '17 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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