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?
[Tex/LaTex] How to refer in the text to a molecule drawn with chemfig
captionschemfigcross-referencing
Related Solutions
Since you can use tikzpictures inside of tikzpictures you can for example define some \circleatom
command and use it inside \chemfig
:
\documentclass{article}
\usepackage{chemfig} % for typesetting molecules
\newcommand*\circleatom[1]{\tikz\node[draw,circle]{#1};}
\begin{document}
\chemfig{CH(-[4]H_2N)(-[6]CH_2(-[6]C(=[5]O)(-[7]OH)))-C(=[2]O)-\circleatom{OH}} % I want to circle this last OH
\chemsign{+}
\chemfig{CH(-[4]\circleatom{H}_2N)(-[6]CH_2(-[6]*6(=-=-=-)))-C(=[1]O)(-[7]O-CH_3)} % I want to circle the H of the H_2N near the beginning
\chemrel{<>} \\
\chemfig{CH(-[4]H_2N)(-[6]CH_2(-[6]C(=[5]O)(-[7]OH)))-C(=[2]O)-N(-[2]H)-CH(-[6]CH_2(-[6]*6(=-=-=-)))-C(=[1]O)(-[7]O-CH_3)}
\chemsign{+}
\chemfig{H_2O}
\end{document}
Edited: a better definition of \circleatom
would be
\newcommand*\circleatom[1]{\tikz\node[circle,draw]{\printatom{#1}};}
The \printatom
will ensure that that aroms are displayed the same if you change it to, say, have sans serif printed atoms.
BTW: I would probably use chemfig
's scheming commands \schemestart
, \arrow
and \schemestop
to typeset the reaction.
\documentclass{article}
\usepackage{chemfig}
\newcommand*\circleatom[1]{\tikz\node[circle,fill=green!30]{\printatom{#1}};}
\setatomsep{2em}
\setcompoundsep{7em}
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}
\begin{document}
\schemestart
\chemfig{CH(-[4]H_2N)(-[6]CH_2(-[6]C(=[5]O)(-[7]OH)))-C(=[2]O)-\circleatom{OH}} % I want to circle this last OH
\+
\chemfig{CH(-[4]\circleatom{H}_2N)(-[6]CH_2(-[6]*6(=-=-=-)))-C(=[1]O)(-[7]O-CH_3)} % I want to circle the H of the H_2N near the beginning
\arrow{<=>}[-90]
\chemfig{CH(-[4]H_2N)(-[6]CH_2(-[6]C(=[5]O)(-[7]OH)))-C(=[2]O)-N(-[2]H)-CH(-[6]CH_2(-[6]*6(=-=-=-)))-C(=[1]O)(-[7]O-CH_3)}
\+
\chemfig{\circleatom{H_2O}}
\schemestop
\end{document}
This is not fully automatic (you need to specify the rotation for the molecule and the corresponding \chemmove
command) and the TikZ code can most likely be improved but it may be a start. It places two invisible bonds where I've marked the respective ends with chemfig
s @{<node name>}
syntax. They are used to draw the rectangle later.
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{chemfig}
\begin{document}
\setatomsep{2em}
\chemfig{
[:-30]*5(
-(=O)-N(
-O(-[::110,2,,,draw=none]@{a})
-[::60](
[::-60]--[::60]--[::60]--[::60]
-(=[::-60]O)(-[::-50,2,,,draw=none]@{b})
-[::60]O-#(,7pt)[::-60]
*5(N-(=O)---(=O)-#(0,5pt))
)=[::60]O
)-(=O)--
)
}
\chemmove[orientation/.style={rotate=0}]{
\draw[orientation,draw=black,opacity=.2,fill=black!30]
(a) -| (b) -| (a)
node[pos=.25,above,opacity=1,orientation]{Some text here} ;
}
\chemfig{
[:0]*5(
-(=O)-N(
-O(-[::110,2,,,draw=none]@{a})
-[::60](
[::-60]--[::60]--[::60]--[::60]
-(=[::-60]O)(-[::-50,2,,,draw=none]@{b})
-[::60]O-#(,7pt)[::-60]
*5(N-(=O)---(=O)-#(0,5pt))
)=[::60]O
)-(=O)--
)
}
\chemmove[orientation/.style={rotate=30}]{
\draw[orientation,draw=black,opacity=.2,fill=black!30]
(a) -| (b) -| (a)
node[pos=.25,above,opacity=1,orientation]{Some text here} ;
}
\chemfig{
[:-60]*5(
-(=O)-N(
-O(-[::110,2,,,draw=none]@{a})
-[::60](
[::-60]--[::60]--[::60]--[::60]
-(=[::-60]O)(-[::-50,2,,,draw=none]@{b})
-[::60]O-#(,7pt)[::-60]
*5(N-(=O)---(=O)-#(0,5pt))
)=[::60]O
)-(=O)--
)
}
\chemmove[orientation/.style={rotate=-30}]{
\draw[orientation,draw=black,opacity=.2,fill=black!30]
(a) -| (b) -| (a)
node[pos=.25,above,opacity=1,orientation]{Some text here} ;
}
\end{document}
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 thechemnum
package.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: