2

I'm writing my chemistry thesis and it involves a lot of reaction schemesA Reaction Scheme How can I add a label that shows up? I want to label the first compound 1, and I want this to be a Latex label so I can refer to it intext and then change the label if need be.

Here's a MWE:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{letterpaper, margin = 1in}
\DeclareFloatingEnvironment[fileext = los, listname = {List of     Schemes}, name = Scheme]{scheme}
\begin{document}
        \begin{scheme}[h!]
            \centering
            \includegraphics[scale = 0.7]{Carbdiazosyn}
            \caption{Generation ...}
            \label{carbdiazosyn}
        \end{scheme}
\end{document}
  • Oops sorry, I'll edit it right away! – thorium Apr 30 '17 at 2:21
  • Not a direct solution, but have you considered using a package like chemfig to draw these reaction schemes? Then you can place labels wherever you want. – Troy Apr 30 '17 at 2:47
  • I find chemfig quite painful to use, especially when the expected standard for my thesis is using ChemDraw, a drag and drop application. I have seen some mention of the psfrag package, but I have no clue if that would work here. – thorium Apr 30 '17 at 3:06
  • FYI: if you want to ping another user you have to put @ followed by the nickname, like @Troy. Otherwise, the user won't be notified. I don't have to use it in my comment to you because I'm making a comment on your post. Using psfrag is probably possible, but I have no experience with it. I'll let someone else do it. I may write up a solution using chemfig just for fun when I have the time later, if no one does so first. – Troy Apr 30 '17 at 7:53
  • Am I right in assuming you want the label to be the name of the molecule? And the label appearing under the molecule itself is okay? Cause your title says next to the figure, and I'm not so sure where that is.. Or it will be nice to draw in (with paint or smth similar) what your desired output is like – Troy Apr 30 '17 at 8:23
3

Chemfig/Chemnum route

the scheme

Probably not the wisest choice to use chemfig, but just showing that it's possible. You would want to use the package chemnum for labelling of the molecules. It offers (among others) the commands:

\cmpd{<main label>.<sublabel>} % <main label> produces the 1, <sublabel> produces the a, b etc.
\refcmpd{<main label>.<sublabel>} % Acts like \ref in normal circumstances

Here's the code:

\documentclass[]{report}
\usepackage{chemfig,chemnum}
\usepackage[version=4]{mhchem}
\usepackage{geometry}
\geometry{letterpaper, margin = 1in}
\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext = los, listname = {List of     Schemes}, name = Scheme]{scheme}

\begin{document}
\begin{scheme}[ht]
    \centering
    %\schemedebug{true}
    \schemestart[0,1.3]
        \chemname{%
            \chemfig{[:120]*3(-[@{a1}]N=[@{db}]N-[@{a2}])%
                (-[:50,,,,red]\textcolor{red}{\ce{R1}})%
                (-[@{r2}:-50,,,,red]\textcolor{red}{\ce{R2}})%
            }
        }{\cmpd{scheme.1}}
        \arrow(.mid east--.mid west){->[$h\nu/\Delta$][$-$\ce{N2}]}
        \chemname{%
            \setlewis{0.8ex}{}{red}%
            \chemfig[shift={(0,0.4)}]{[:-30]\textcolor{red}{\ce{R1}}%
                -[,,,,red](\lewis{6:,})%
                -[::60,,,,red]\textcolor{red}{\ce{R2}}}%
        }{\cmpd[pre-label-code{scheme.2}}
    \schemestop
    \chemmove{%
        \draw[shorten <=2pt, shorten >=3pt]%
            (a1)..controls +(250:3mm) and +(340:3mm)..(db);
        \draw[shorten <=2pt, shorten >=2pt]%
            (a2)..controls +(320:3mm) and +(210:2mm)..(r2);
        }
    \caption[]{My scheme}\label{scheme1}
\end{scheme}
The arrows in \refcmpd{scheme.1} refer to electron movement! The compound in \refcmpd{scheme.2} is in red! Both \refcmpd{scheme.1, scheme.2} are in scheme \ref{scheme1}.
\end{document}

Point to note: I used the commands from chemnum within the \chemname command to insert the 'labels'. I also used the mhchem package to typeset the compound names within chemfig. The rest is just chemfig code. :-).


Auto-pst-pdf/Chemnum route (Probably recommended)

The chemnum package also documents a way to replace tags of the .eps figure in Section 9, pg18 of the documentation. According to the manual, the workflow for this is (quoting verbatim):

  1. Create the scheme and place temporary tags like TMP1, TMP2 and so on where you want the compound labels to be.
  2. Export the scheme as eps or ps figure where you make sure that the tags are embedded as text strings.
  3. Include the eps with \includegraphics. Right before that use \replacecmpd once for every temporary tag.

I personally have not tried this (as I don't use chemdraw), so I will just refer you to the documentation. (Perhaps another answer properly documenting this method is needed). Anyhoo, as the documentation suggests, I think this is the way to go if you want to continue using chemdraw.

Here's an example code from the documentation:

 % code for figure 2
 \documentclass{standalone}
 \usepackage{graphicx,auto-pst-pdf,chemnum}
 \begin{document}
 \replacecmpd{Alc}% replaces TMP1
 \replacecmpd{EtherBr}% replaces TMP2
 \includegraphics{scheme-tmp.ps} % Contains TMP1 and TMP2 as embedded text strings
 \end{document}
  • You should probably mention that auto-pst-pdf is needed to be able to use psfrag (loaded internally by chemnum for doing the actual replacement) with pdflatex and that auto-pst-pdf needs shell-escape enabled… – clemens May 1 '17 at 10:50
  • Actually, I'm not all too familiar with this. If you'ld like, you can write up a separate answer on this? I don't think my current answer (on auto-pst-pdf) sufficiently answers OP's question. If you do, then I'll delete the second half of my answer. – Troy May 1 '17 at 10:55
2

I had to tweak the widths to get the subcaptions to fit.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{letterpaper, margin = 1in}
\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext = los, listname = {List of     Schemes}, name = Scheme]{scheme}
\usepackage{graphicx}
\usepackage{subcaption}
\DeclareCaptionSubType{scheme}
\captionsetup[subscheme]{font+=footnotesize}
\begin{document}
        \begin{scheme}[htp]% h! is interpreted as "I am an idiot so replace this with something reasonable"
            \centering
            \sbox0{\includegraphics[scale = 0.7]{images/Carbdiazosyn}}% measure width
            \usebox0\par
            \makebox[1.1\wd0]{\parbox{0.45\wd0}{\subcaption{Compound 1}\label{compound1}}\hfill
              \parbox{0.45\wd0}{\subcaption{Compound 2}\label{compound2}}}
            \caption{Generation ...}
            \label{carbdiazosyn}
        \end{scheme}

\centering Of course, the reference will only return \ref{compound1}.
\end{document}

demo


Since captions are designed to fit into a given space and in this case we want them to fit on one line, it is easier to not use the subcaption package.

A number of formatting options are possible. In this case, I put the caption to the left but left the image centered.

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\geometry{letterpaper, margin = 1in}
\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext = los, listname = {List of     Schemes}, name = Scheme]{scheme}
\usepackage{graphicx}

\newcounter{compound}
\newcommand{\compound}[1]% #1 = label
{\refstepcounter{compound}\label{#1}Compound \thecompound}

\begin{document}
        \begin{scheme}[htp]
            \centering
            \leavevmode\llap{\compound{test}:\qquad}%
            \raisebox{-0.5\height}{\includegraphics[scale = 0.7]{images/Carbdiazosyn}}% center
            \caption{Generation ...}
            \label{carbdiazosyn}
        \end{scheme}

\centering This references the compound index, \ref{test}.
\end{document}

demo2

  • thanks @John ! This is an interesting way of doing it. Forgive me if these questions are silly, but I'm quite inexperienced with Latex: 1. Why is h! so bad, and how is htp better? 2. What does the \leavemode do? 3. How can I center the numbering (below the molecule, instead of to its left)? 4. Finally, do I need a new command for evey new molecule I need to number? Thanks for your help!! – thorium Apr 30 '17 at 18:16
  • 1. Actually [h!] is better than [h], since [h!] is equivalent to [ht] IIRC. 2. \llap and \rlap do odd things in vmode (at the start of a line). 3. What exactly do you want to center the numbering below? The whole image or just part of it? 4. Probably not. that's part of what counters do. – John Kormylo Apr 30 '17 at 21:57
  • Thanks @John. I was just hoping to center the label for part of the image. So "Compound:1" could be below the actual compound, centered. – thorium Apr 30 '17 at 22:09
  • In that case, you need to know how wide each part is. I can compute the width of the whole thing, but the parts? – John Kormylo Apr 30 '17 at 22:57

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.