[Tex/LaTex] How to refer in the text to a molecule drawn with chemfig

captionschemfigcross-referencing

I just found chemfig fantastic for drawing even difficult molecules. Now, I have a question: how can I put under the molecule a line with a caption like "Figure #: captiontext" and, even more important, how can I refer in the text to the drawn molecule?

Best Answer

I must confess the question is a bit unclear to me but it seems like you simply want a {figure} environment. If by Ā»refer to the [...] moleculeĀ« you mean the practice of refering to molecules with numbers in the text you may want to have a look at the chemnum package.

\documentclass{article}
\usepackage{chemfig}
\usepackage{chemnum}
\newcommand*\pkg[1]{\textsf{#1}}
\begin{document}

\begin{figure}
  \centering
  \chemfig{-[:30](=[:90]O)-[:-30]OH}
  \caption{The sceletal formula of ethanol (\cmpd{ethanol}) drawn with
    \pkg{chemfig}.}
  \label{fig:ethanol}
\end{figure}

The formula of \cmpd{ethanol} is shown in figure~\ref{fig:ethanol}.

\end{document}

enter image description here

Caution: the number of the molecule is determined by the first use of the corresponding \cmpd. This means it may haben in the \listoffigures if you use \cmpd in a caption. For cases like this there is \cmpd+ which only fetches the number:

\begin{figure}
  ...
  \caption{... ethanol (\cmpd+{ethanol}) ...}
\end{figure}

The formula of \cmpd{ethanol} ...
Related Question