The chemfig package
Draws structural formulas of molecules with \chemfig: atoms, single, double and triple bonds at chosen angles, rings and reaction schemes.
Loading the package
\usepackage{chemfig}mhchem writes formulas in one line. chemfig draws the molecule in two dimensions. You describe it as a chain: atoms separated by bond symbols (-, =, ~), a direction in square brackets after the bond, and parentheses for a branch that leaves the chain.
[2] after a bond means 2 × 45°, so the bond points up; [:30] gives an angle in degrees. A ring is *6(...) with the six bonds listed in the parentheses. Atoms are set in math mode, so CH_3 gives a subscript 3.
The package draws with tikz and loads it.
Main commands
\chemfig{A-B=C~D} | Chain with a single, a double and a triple bond. |
\chemfig{A-[2]B} | Bond in direction 2 × 45° = 90°, straight up. [0] to [7] cover the eight directions. |
\chemfig{A-[:30]B} | Bond at an angle of 30° to the horizontal. |
\chemfig{C(-[2]H)(-[6]H)-H} | Each pair of parentheses is a branch that starts at the atom before it. |
\chemfig{*6(-=-=-=)} | Ring with six atoms and alternating double bonds (benzene). |
\setchemfig{atom sep=2em} | Sets options for the following molecules, here the bond length. |
\schemestart A \arrow{->[heat]} B \schemestop | Reaction scheme: compounds joined by arrows with a label. |
Complete example
\documentclass{article}
\usepackage{chemfig}
\begin{document}
Ethanol: \chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-O-H}
\bigskip
Acetic acid: \chemfig{CH_3-C(=[1]O)-[7]OH}
\qquad
Benzene: \chemfig{*6(-=-=-=)}
\bigskip
\schemestart
\chemfig{CH_3-CH_2-OH}
\arrow{->[oxidation]}
\chemfig{CH_3-C(=[1]O)-[7]H}
\schemestop
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
- Settings go through
\setchemfig{key=value}. The commands\setatomsepand\setbondoffsetfrom older tutorials no longer exist and give Undefined control sequence. - A direction applies to one bond. The next bond without brackets points to the right again, as in
\chemfig{A-[2]B-C}, where C stands to the right of B. A zigzag chain needs an angle at every bond.
Related pages
- How-to Chemical formulas and reactions in LaTeX
- Package
mhchem - Package
tikz