8

this question has been asked in this link: Forked arrows with chemfig It is very helpful for me. I would like to thank Gonzalo Medina for his solution. However, I have two questions that I cannot find any solution anywhere.

1) How to make \chemfig work properly inside tikzpicture? I want to have a chemical structure (which is drawn by chemfig) above and below the arrow. However when I use \chemfig{...} all the bonds turn to arrow. I think it is because this command stays inside the \draw command.

2) How can I change the length of only the arrow part (the line still the same) to fit the content of the node above/ below the arrow.

Here is the scheme I want to make: enter image description here

Thanks a ton!

Here is my tex file:

\documentclass[class=minimal,border=0pt,10pt]{standalone}%[a4paper]
\usepackage{chemfig,chemmacros}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[node distance=0cm and 2cm]
    %\tikzset{myarrow/.style={->, >=latex', shorten >=1pt, thick},mylabel/.style={text width=7em, text centered} }  
\setcrambond{4pt}{}{}
%\setarrowoffset{10pt}
\node (A)
{\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]HO)-[:15,,,,line width = 4pt](-[:-60,0.6]OH)>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off  2pt])-[:120]O-[:-165]?[A]}};
%===================================
\node [above right= of A](B)
{\hspace{2cm}\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-90,0.5]-[:-130,0.5](-[:-80,0.6]\chemabove{O}{\hspace{4mm}\scriptstyle\ominus})=[:160,0.6]O))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off 2pt])-[:120]O-[:-165]?[A]}};
%===================================
\node[below=of B, align=left](B1){R=H or \ch{CH2COONa} \\depending on DS}; %align=left to use \\ inside node
%===================================
\node[below=0.5 of B1](C)
{\hspace{2cm}\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-120,0.5]-[:-60,0.5](-[,0.4]OR)-[:-120,0.5]-[:-60,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{4mm}\scriptstyle\ominus}))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off 2pt])-[:120]O-[:-165]?[A]}}; %{(} or {)} for sth like N(CH3)3Cl inside chemfig 
%===================================
\node[below=of C, align=left](C1)
{\hspace{1cm} R=H, \chemfig{-[:30,0.5](-[:90,0.4]OR)-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}\\ \hspace{1.1cm}depending on MS};
%===================================
\node[below=0.5 of C1](D)
{\hspace{2cm}\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-30,0.6]SO_3Na))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off    2pt])-[:120]O-[:-165]?[A]}};
%===================================
\node[below=of D](D1)
{R=H, \ch{SO3Na}};
%===================================
\node[below=0.5 of D1](E)
{\hspace{3cm}\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-30,0.5]-[:30,0.5]-[:-30,0.5]-[:30,0.5]-[:-30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off 2pt])-[:120]O-[:-165]?[A]}};
%===================================
\node[below=of E](E1)
{R=H, \chemfig{(=[:90,0.4]O)-[:-30,0.5]-[:30,0.5]-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}};
%\draw[myarrow] (A.east) -- ++(0.5,0) -- ++(0,1) |-(B.west);    
%===================================
\draw[-stealth](A) --($(A.0)!0.5!(B.west|-A.0)$) |- (B.west) node[above]{\ch{ClCH2COONa}}node[below,align=left]{aq. \ch{NaOH}\\slurry medium};
%===================================
\draw[-stealth](A) -- ($(A.0)!0.5!(C.west|-A.0)$) |- (C.west) node[above]{\chemfig{?-[:90,0.5]O-[:-30,0.5]?-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}} node[below,align=left]{aq. \ch{NaOH}\\slurry medium};
%===================================
\draw[-stealth](A) -- ($(A.0)!0.5!(D.west|-A.0)$) |- (D.west) node[above,align=left]{(i) \ch{SO3}.DMF or \ch{SO3}.pyridine\\(DMF/LiCl) 50 \si{\degreeCelsius})}node[below,align=left]{(ii) \ch{NaOH}};
%===================================
\draw[-stealth](A) -- ($(A.0)!0.5!(E.west|-A.0)$) |- (E.west) node[above,align=left]{\chemfig{HO-[:30,0.5](=[:90,0.4]O)-[:-30,0.5]-[:30,0.5]-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}}node[below,align=left]{DMSO, CDI \\ 20 h, 70 \si{\degreeCelsius}}; 

\end{tikzpicture}
\end{document}
8
  • 1
    Please mark your code with four spaces as code to make it readable.
    – Carina
    Feb 16, 2016 at 13:40
  • 1
    Your code does not compile, I'm getting 12 errors, please make sure it's compilable.
    – Alenanno
    Feb 16, 2016 at 13:41
  • @Carina: sorry I don't understand. what do you mean by saying "four spaces"?
    – Chung
    Feb 16, 2016 at 13:50
  • 1
    Possible duplicate of Forked arrows with chemfig Feb 16, 2016 at 16:02
  • 1
    @StefanPinnow: it is the same topic but my questions are different. I could not figure it out with the previous link
    – Chung
    Feb 16, 2016 at 16:43

1 Answer 1

3

To 1) Here you simply need to add the optional argument [-] to the \chemfig command to "remove" the arrow heads from the "draw line" command.

To 2) Here I suggest to do that "manually". First place the top most node by using the =<number>cm and <number>cm of <node> feature, then decide with the created \split variable where the path to this node should be "split" and decide with the created \xshift variable the offset of the nodes placed above and below the arrow. While drawing the reaction scheme you can simply adjust the node positions on the right and/or by adjusting the \split ratio to fit your needs.

Here is a simplyfied reaction scheme as demonstration for the above said.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{chemfig}
\usepackage{chemformula}
    \usetikzlibrary{arrows,positioning,calc}
\usepackage{siunitx}
\begin{document}
    \begin{tikzpicture}
            \setcrambond{4pt}{}{}
            \pgfmathsetlengthmacro{\xshift}{1cm}
            \pgfmathsetmacro{\split}{0.1}

        \node (A) {A};
        \node [above right=2cm and 5cm of A](B) {B};

        \draw[-stealth](A) --($(A.0)!\split!(B.west|-A.0)$) |- (B.west)
                % just to show the alignment point for the following nodes
                coordinate [pos=0.5,xshift=\xshift] (test)
            node [pos=0.5,xshift=\xshift,above,anchor=south west]
                {\ch{ClCH2COONa}}
            node [pos=0.5,xshift=\xshift,below,anchor=north west]
                {\chemfig[-]{?-[:90,0.5]O-[:-30,0.5]?-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}};
                % show the alignment points
                \fill [red] (test) circle (2pt) -- +(-1cm,0) circle (2pt);
    \end{tikzpicture}
\end{document}

image showing result of simplified reaction scheme code


And here you can find your full reaction scheme, where I in addition have cleaned up some non-necessary \hspaces and set proper alignments of the nodes.

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage{chemfig}
\usepackage{chemformula}
    \usetikzlibrary{arrows,positioning,calc}
\usepackage{siunitx}
\begin{document}
    \begin{tikzpicture}[
        >=stealth,
        shorten >=1mm,
        component node/.style={
            % keys for `\chemfig'
            -,
            shorten >=0pt,
%            % fill the nodes (useful for debugging)
%            fill=red!50,
        },
        arrow node/.style={
            pos=0.5,
            xshift=\xshift,
            align=left,
            % keys for `\chemfig'
            -,
            shorten >=0pt,
        },
    ]
            \setcrambond{4pt}{}{}
            \pgfmathsetlengthmacro{\xshift}{1mm}
            \pgfmathsetmacro{\split}{0.1}

    % left side of reaction scheme
        \node [component node] (A)
            {\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]HO)-[:15,,,,line width = 4pt](-[:-60,0.6]OH)>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off  2pt])-[:120]O-[:-165]?[A]}};

    % right side of reaction scheme
        \node [component node,above right=2cm and 6cm of A] (B)
            {\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-90,0.5]-[:-130,0.5](-[:-80,0.6]\chemabove{O}{\hspace{4mm}\scriptstyle\ominus})=[:160,0.6]O))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off 2pt])-[:120]O-[:-165]?[A]}};
        \node [component node,below=0 of B.south west,anchor=north west,align=left] (B1)
            {R=H or \ch{CH2COONa} \\ depending on DS}; %align=left to use \\ inside node

        \node [component node,below=0.5 of B1.south west,anchor=north west] (C)
            {\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-120,0.5]-[:-60,0.5](-[,0.4]OR)-[:-120,0.5]-[:-60,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{4mm}\scriptstyle\ominus}))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off 2pt])-[:120]O-[:-165]?[A]}}; %{(} or {)} for sth like N(CH3)3Cl inside chemfig
        \node [component node,below=0 of C.south west,anchor=north west, align=left](C1)
            {R=H, \chemfig{-[:30,0.5](-[:90,0.4]OR)-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}\\ \hspace{1.1cm}depending on MS};

        \node [component node,below=0.5 of C1.south west,anchor=north west](D)
            {\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-30,0.6]SO_3Na))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off    2pt])-[:120]O-[:-165]?[A]}};
        \node [component node,below=0 of D.south west,anchor=north west] (D1)
            {R=H, \ch{SO3Na}};

        \node [component node,below=0.5 of D1.south west,anchor=north west] (E)
            {\chemfig{-[:-15,0.5,,,dash pattern = on 2pt off 2pt]O-[:15,0.5]?[A]<[:-60](-[:165,0.6]RO)-[:15,,,,line width = 4pt](-[:-60,0.6]O(-[:-30,0.5]-[:30,0.5]-[:-30,0.5]-[:30,0.5]-[:-30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}))>[:-15](-[:15,0.5]O-[:-15,0.5,,,dash pattern=on 2pt off 2pt])-[:120]O-[:-165]?[A]}};
        \node [component node,below=0 of E.south west,anchor=north west](E1)
            {R=H, \chemfig{(=[:90,0.4]O)-[:-30,0.5]-[:30,0.5]-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}};

    % draw reaction arrows + nodes
        %\draw[myarrow] (A.east) -- ++(0.5,0) -- ++(0,1) |-(B.west);
        \draw [->] (A) -- ($(A.east)!\split!(B.west|-A.east)$) |- (B.west)
            node [arrow node,above right]
                {\ch{ClCH2COONa}}
            node [arrow node,below right]
                {aq. \ch{NaOH}\\slurry medium};
        \draw [->] (A) -- ($(A.east)!\split!(C.west|-A.east)$) |- (C.west)
            node [arrow node,above right]
                {\chemfig[-]{?-[:90,0.5]O-[:-30,0.5]?-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}}
            node [arrow node,below right]
                {aq. \ch{NaOH} \\ slurry medium};
        \draw [->] (A) -- ($(A.east)!\split!(D.west|-A.east)$) |- (D.west)
            node [arrow node,above right]
                {(i) \ch{SO3}.DMF or \ch{SO3}.pyridine\\(DMF/LiCl) \SI{50}{\degreeCelsius})}
            node [arrow node,below right]
                {(ii) \ch{NaOH}};
        \draw [->] (A) -- ($(A.east)!\split!(E.west|-A.east)$) |- (E.west)
            node [arrow node,above right]
                {\chemfig[-]{HO-[:30,0.5](=[:90,0.4]O)-[:-30,0.5]-[:30,0.5]-[:-30,0.5]-[:30,0.6]\chemabove{N}{\hspace{-5mm}\scriptstyle\oplus}{(}CH_3{)}_3\chemabove{Cl}{\hspace{5mm}\scriptstyle\ominus}}}
            node [arrow node,below right]
                {DMSO, CDI \\ \SI{20}{\hour}, \SI{70}{\degreeCelsius}};
    \end{tikzpicture}
\end{document}

image showing result of full reaction scheme

3
  • wow..what a wonderful work. It looks quite complicated for me...but I will definitely learn from it. Thank you thousand times. Just wanna add something here. I didn't know that the number between (..) in the code: $...$ was to specify the point for splitting as well. So, I just figured out how to adjust the length of the arrow part as I mentioned in my second question. Thanks thanks thanks :-)
    – Chung
    Feb 16, 2016 at 18:43
  • @Chung, you are welcome. I think "my work" was the easy part of the picture. I would have never been able to draw the \chemfigs. What really helps to figure out how tikz works is to do and understand the first tutorials in the pgf manual (sections 2 to 5, if you don't need mindmaps). Maybe you have to do them twice, but there will come the time it makes "click" and you'll have a really good understanding what is going on and how to achieve stuff. Feb 16, 2016 at 19:01
  • you are right. I will definitely read and practice the instruction. By the way, it is really fun to play with chemfig. I am getting better in drawing chemical structures and really happy about that. I hope that I can help you later :-) Thanks again..I wish I could vote for more than 1 time :D
    – Chung
    Feb 16, 2016 at 19:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .