[Tex/LaTex] Using the mhchem and chemfig packages in conjunction

chemfigchemistrymhchem

I am trying to write a chemical reaction in which I want to include a chemical structure. I am having some trouble regarding alignment and bond length. Here is a minimal working example:

\documentclass[a4paper,article]{memoir}

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

\begin{document}
\ce{3CH3CHOHCH3 + Cr2O7^{2-} -> 3\chemfig{C(-[:0]CH_3)(-[:180]CH_3)(=[:270]O)} + 2Cr^{3+} + 7H2O}
\end{document}

Which produces the following output:

The problems I'm having are:

  • Bond length: Despite the two CH3 groups being identical, the bond lengths are not the same. Scaling each bond individually would be somewhat of a hassle (this is one of the simpler structures I'm working with), so I would prefer if there were some way to ensure constant bond length.
  • Alignment with the rest of the reaction: It seems like the bottom of the subscript "3" aligns with the baseline of the rest of the reaction, which I would like to avoid. Is there any way to (preferably automatically, but I'll take what I can get) align the baseline of the upper row of the structure with the baseline of the rest?
  • Height of subscripts: The subscripts created by the mhchem package are different in height to the ones created by the chemfig package. I have tried including \ce commands in the \chemfig command, but it seems like chemfig treats the formulas produced this way as images, which gets in the way of aligning bonds to specific atoms. This also messes with the vertical location of the bonds relative to the CH3 groups.

I know that chemfig can also be used to typeset reactions, but looking at things like this, it seems that mhchem is much more user-friendly in this regard.

Any help with this would be much appreciated.

Best Answer

Bundling my comments into an answer:

  • I wrote »There is no way to make chemfigs bonds all the same length. Quoting part II section 4 Length of a bond of chemfig's manual:«

    Rather than speaking of length of a bond, we should use the term interatomic spacing. If effect, only the interatomic spacing is adjustable with \setatomsep as we have seen on page 6. Once this parameter is set, the length of a bond depends on the content of atoms and, to a lesser extent, the angle the bond makes with the horizontal. It should be obvious that two “slimmer” atoms will have larger edge separations than two which are larger.

    While this was true at the time I wrote my comment meanwhile there has been an update to chemfig. Since version 1.1 the following is possible:

    When a star follows the macro \chemfig*, the bonds have a fixed length and therefore, the distance between center to center atoms becomes variable. The macro \enablefixedbondlength makes this behavior valid for all macros (starred or not) while \disablefixedbondlength goes back to the default behavior. [...] In rings, even with starred \chemfig*, the default behaviour is restored in order to draw regular polygons.

  • Regarding your second point part III section 4 Vertical alignment has some information. It will not be immediately helpful, though, I guess. Nonetheless it is important information. The solution for the formula in your question is simple, though: write your formula in a different way:

    \chemfig{CH_3-C(=[6]O)-CH3}
    

    Keep in mind that the first atom in a formula determines the baseline of the whole formula.

  • As for your third point I recommend reading the blog post “Exploring ChemFig: Customising appearance” of our own @JosephWright which explains a method of how to use mhchem's \cf inside chemfig's \printatom. The crucial part is a redefinition of \CF@node@content

    \makeatletter
    \def\CF@node@content{%
      \expandafter\expandafter\expandafter
        \printatom\expandafter\expandafter\expandafter
          {\csname atom@\number\CF@cnt@atomnumber\endcsname}%
        \ensuremath{\CF@node@strut}%
    }
    \makeatother
    

    which then allows \renewcommand*{\printatom}[1]{{\sffamily\cf{#1}}} for example.

Related Question