5

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}
6

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}
  • Why not \chemfig{H-[:30](=[:90]O)-[:-30]OH}? – cgnieder Nov 10 '15 at 14:26
  • 3
    And maybe align the arrow, too: \arrow(.base east--.base west){<=>[][][4pt]} – cgnieder Nov 10 '15 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 Nov 10 '15 at 14:38
  • 1
    @ArchStanton I find it much nicer if the letters are aligned :) – cgnieder Nov 10 '15 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 Nov 11 '15 at 12:53
-1

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

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

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.