6

I use the chemfig package to draw molecules in a chemical reaction. However, I cannot align the molecules, the + sign and arrow at the base line. I have tried the \vphantom command, like in this question. But it does not work. I cannot use the \chemfig{} command to shift the molecules up or down. How could I handle this type of problem when using chemfig? Any tricks for new chemfig learners? Here's my output so far: enter image description here

My code:

\documentclass{article}
\usepackage{chemfig}
\begin{document}
\setatomsep{3em}
\schemestart
\chemname{\chemfig{O=[:-90](-[:-150]H)-[:-30]OH}}{Formic acid} 
\+{2em, 2em, -3em} 
\vphantom{\+{,, -3em}}%
\chemname{\chemfig{CH_3OH}}{Methanol}
\arrow{<=>}
\chemname{\chemfig{O=[:-90](-[:-150]H)-[:-30]O-[:30]}}{Methyl formiate} 
\+{2em, 2em, -3em} 
\chemname{\chemfig{H_2O}}{Water}
\schemestop

\end{document}

2 Answers 2

9

chemfig always places the first atom of the molecule on the baseline, so if you write

\chemfig{O=[:-90](-[:-150]H)-[:-30]OH}

the oxygen will be on the baseline. To put the carbon on the baseline it has to be the first atom:

\chemfig{(-[:-150]H)(=[:90]O)-[:-30]OH}

In other words, you must start from the atom you want to be on the baseline and treat the others like branchings. The code is therefore

\documentclass{article}
\usepackage{chemfig}
\begin{document}
\setatomsep{3em}
\schemestart
\chemname{\chemfig{(-[:-150]H)(=[:90]O)-[:-30]OH}}{Formic acid}
\+
\chemname{\chemfig{CH_3OH}}{Methanol}
\arrow{<=>}
\chemname{\chemfig{(-[:-150]H)(=[:90]O)-[:-30]O-[:30]}}{Methyl formiate}
\+
\chemname{\chemfig{H_2O}}{Water}
\schemestop
\end{document}
9
  • Why not \chemfig{H-[:30](=[:90]O)-[:-30]OH}?
    – cgnieder
    Commented Nov 10, 2015 at 14:26
  • 3
    And maybe align the arrow, too: \arrow(.base east--.base west){<=>[][][4pt]}
    – cgnieder
    Commented Nov 10, 2015 at 14:27
  • @arch Stanton: Thanks for your reply. It works, but the name the names below the molecules are a little far away. any idea to tackle this?
    – Nick
    Commented Nov 10, 2015 at 14:38
  • 1
    @ArchStanton I find it much nicer if the letters are aligned :)
    – cgnieder
    Commented Nov 10, 2015 at 15:40
  • 1
    @Nick my answer would basically be the same as Arch's: change the definition of the molecules appropriately so their baseline is changed which then will make alignment easier. I'm not sure this justifies a new answer…
    – cgnieder
    Commented Nov 11, 2015 at 12:53
-2

Chemical formula are very difficult to do properly even with a good package like Chemfig. I would switch to a dedicated application like ChemDraw which has all of the functionality that you need for this problem as well all the extras for other more complex examples.

Sometimes one has to recognise that TeX/LaTeX cannot do it all ... more's the pity

3
  • 1
    That's a valid opinion and I even agree but it doesn't answer the question!
    – cgnieder
    Commented Nov 11, 2015 at 12:12
  • Chemfig can do what the OP has asked (and much more). Commented Nov 11, 2015 at 16:48
  • "Horses for courses" Commented Nov 12, 2015 at 13:32

You must log in to answer this question.

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