# Using tikz-cd to draw a complex reaction network

I am trying to draw the following schematic (generated using ChemDraw) using tikzcd.

Here's is what I have so far.

I don't understand how the positioning of labels above and below the arrows seems to work in tikzcd environment. My MWE so far is as follows.

\documentclass[9pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{cd,positioning}%cd is for commutative diagrams
\usepackage{color}
\usepackage[version=4]{mhchem}
\renewcommand*{\familydefault}{\sfdefault}
\usepackage{sfmath}
\begin{document}
\begin{tikzcd}[column sep=large]
& \ce{CH3+ + H2O}  & &\\
\ce{CH3-OH} \ar[ur,"\ce{\color{gray}dehydration}" sloped, pos=1, "\ce{H+}"',sloped,pos=0.5] \ar[dr,"\ce{\color{gray}transfer\\[-0.5em]\color{gray}dehydrogenation}"' sloped, align=center,pos=1,"\ce{R+}",sloped,pos=0.5] & &\ce{R+} \equiv \ce{alkoxide} \\
& \ce{CH2OH+ + paraffins}  & &
\end{tikzcd}
\end{document}


I am not sure how to align the first and third row elements such that the 'C's of CH3+ and CH2OH+ align. Also positioning a label below the ur or dr arrows seems to work mysteriously because I am able to position one label at a time halfway on the arrow but putting the label below seems to move the label above towards the arrow start.

I am open to suggestions if there are other packages which might help me create this diagram more easily.

• I guess it is more doable if you just forget tikz-cd and do it with pure TikZ. – Symbol 1 Jun 14 '17 at 1:10

If you assume that tikzcd places the quote fields from left to right regardless whether they are above or below the line, then to overlap them you would have to use something like \llap or \rlap, only centered. Note that the pos and sloped arguments are all in the same \ar[...], so I doubt trying to use more than one definition will work.

\documentclass[9pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{cd,positioning}%cd is for commutative diagrams
\usepackage{color}
\usepackage[version=4]{mhchem}
\renewcommand*{\familydefault}{\sfdefault}
\usepackage{sfmath}

\newcommand{\clap}[1]% #1 = multiline text to be centered in zero width field
{\bgroup
\sbox0{\begin{tabular}{@{}c@{}}#1\end{tabular}}%
\hspace{-0.5\wd0}\usebox0\hspace{-0.5\wd0}%
\egroup}

\begin{document}

\begin{tikzcd}[column sep=large]
& \ce{CH3+ + H2O}  & &\\
\ce{CH3-OH} \ar[ur,sloped,pos=0.4,"\clap{\ce{\color{gray}dehydration}}",
"\clap{\ce{H+}}"']
\ar[dr,sloped, align=center,pos=0.4,"\clap{\ce{\color{gray}transfer}\\[-0.5em]\ce{\color{gray}dehydrogenation}}"',
"\clap{\ce{R+}}"]
& &\ce{R+} \equiv \ce{alkoxide} \\
& \ce{CH2OH+ + paraffins}  & &
\end{tikzcd}
\end{document}


This solution uses tikz matrix instead. You have to draw the lines separately, and reserve space for them explicitly (hence the \phantom). I used math nodes since everything except the \equiv is inside \ce{...}.

\documentclass[9pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}%cd is for commutative diagrams
\usepackage{color}
\usepackage[version=4]{mhchem}
\renewcommand*{\familydefault}{\sfdefault}
\usepackage{sfmath}

\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, row sep=1ex]{
& & \ce{CH3+ + H2O}  &\\
\ce{CH3-OH} & \phantom{\footnotesize\ce{dehydrogenation}} & & \ce{R+} \equiv \ce{alkoxide} \\
& & \ce{CH2OH+ + paraffins}  & \\
};
\draw[->] (m-2-1) -- (m-1-3.west)
node[above,pos=0.5,sloped,font=\footnotesize,text=gray] {\ce{dehydration}}
node[below,pos=0.5,sloped,font=\footnotesize] {\ce{H+}};
\draw[->] (m-2-1) -- (m-3-3.west)
node[above,pos=0.5,sloped,font=\footnotesize] {\ce{R+}}
node[below,pos=0.5,sloped,font=\footnotesize,text=gray,align=center] {\ce{transfer}\\[-0.5em]\ce{dehydrogenation}};
\end{tikzpicture}
\end{document}


• this works great! Just to add to your solution, is there a way to align the C's of CH3+ and CH2OH+ in the first and third row; and can the arrow head be placed close to the mid of C's? – scorpionwars Jun 14 '17 at 12:21
• Alas, the arrows go from center to center. OTOH, \rlap would put the center on the left. You really should use matrix instead. – John Kormylo Jun 14 '17 at 13:12
• The matrix solution is more elegant and allows more control over the node placement than the tikz-cd environment. Thanks a lot! – scorpionwars Jun 14 '17 at 16:33