2

For a beamer presentation I want to apply the nice chemformula package. I now wish to have only the coefficients colored individually, for example marking the first coefficient in blue:

\ch{\color{blue}106 CO2 + 122 H2O + 16 HNO3 + H3PO4 -> (CH2O)106 + (NH3)16(H3PO4) + 138 O2}

As soon as I include the \color command (as explained in the chemformula manual), the coefficient becomes a subscript. I also tried

\ch{ \textcolor{blue}{106} CO2 + 122 H2O + ...,

which generates the same result. The equation looks fine when I omit any attempt coloring the coefficients. What am I missing here? I assume that there is a very simple solution to this problem. Any advice is much appreciated, thanks. Markus

2 Answers 2

4

A stoichiometric factor may only contain numbers and the signs . ,_ /().

As alternative you might prevent chemformula from parsing the input, for example using \ch{"⟨escaped text⟩"}

Compounds are more straightforward. (Third formula)

b

\documentclass[11pt]{beamer}

\usepackage{lmodern}
\usetheme{default}

\usepackage{chemformula}
\begin{document}
    \begin{frame}
        \frametitle{}
        \ch{106 CO2 + 122 H2O + 16 HNO3 + H3PO4 -> (CH2O)106 + (NH3)16(H3PO4) + 138 O2}\bigskip     
        
        \ch{"\color{blue}" 106}\ch{CO2 + 122 H2O + 16 HNO3 + H3PO4 -> (CH2O)106 + (NH3)16(H3PO4) + 138 O2}\bigskip
        
        \ch{106 \color{red}CO2 + 122 H2O + 16 HNO3 + H3PO4 -> (CH2O)106 + (NH3)16(H3PO4) + 138 O2}
        
    \end{frame}
\end{document}
0

With an up to date chemformula you can set the option stoich-format. You can set it locally using chemformula's @{...} syntax:

\documentclass{beamer}
\usepackage{chemformula}

\begin{document}

\begin{frame}
  \ch{
    @{stoich-format=\color{blue}} 106 CO2 + 122 H2O + 16 HNO3 + H3PO4
    ->
    (CH2O)106 + (NH3)16(H3PO4) + @{stoich-format=\color{blue}} 138 O2
  }
\end{frame}

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