Example: Drawing molecules

Published 2015-09-25 | Author: Stefan Kottwitz

In the Chemical formulae example we already encountered formulae for molecules. Now we like to see how to draw them. This means drawing a group of atoms and connecting them by lines of various kinds.

This rather complex seeming task becomes manageable using the chemfig package. It provides a compact syntax for drawing molecules.

The chemfig package internally uses TikZ for drawing. It automatically takes care of the bounding box, so the drawing would not overlap other text. Advanced users could even insert TikZ code.

The main command is \chemfig, it takes an argument consisting of

  • letters for atoms
  • symbols for bonds, such as -, -, and ~ for simple, double and triple bonds
  • options in square brackets, separated by comma
  • branches of atoms and bonds within parentheses

The code is fully explained in the LaTeX Cookbook, Chapter 11, Science and Technology, Drawing molecules.

Download as: [PDF] [TEX]  •  [Open in Overleaf]

Drawing molecules
% Drawing molecules
% Author: Stefan Kottwitz
% https://www.packtpub.com/hardware-and-creative/latex-cookbook
\documentclass[border=10pt]{standalone}
\usepackage{chemfig}
\begin{document}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{rl}
  Hydrogen: & \chemfig{H-H} \\
  Oxygen:   & \chemfig{O=O} \\
  Ethyne:   & \chemfig{H-C~C-H}
\end{tabular}
\qquad
Methane: \chemfig{[,0.8]C(-[2]H)(-[4]H)(-[6]H)-H}
\end{document}

Comments

Adding comments is currently not enabled.

There are currently 0 comments on this entry.

Features
Tags
Scientific and technical areas
LaTeX Cookbook

Cookbook

LaTeX Beginners Guide

Creative Commons License