Example of how to add TikZ arrows to chemical reactions made with the mhchem package. TikZ coordinate nodes are put in the reaction equations and later used as reference points for drawing using TikZ’s remember picture feature.
Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the
LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.
En français: TeXnique.fr.
% Oxidation and reduction
% Author: Arne Röhrs
% Note that two compilations are necessary.
\documentclass{article}
\usepackage{tikz}
\usepackage[version=3,arrows=pgf]{mhchem}
\begin{document}
% Insert a named coordinate for later reference.
% Usage:
% \ncoord{name}
% \ncoord[1em,2em]{name}
\newcommand\ncoord[2][0,0]{%
\tikz[remember picture,overlay]{\path (#1) coordinate (#2);}%
}
% Define a handful of special cases of \ncoord
\newcommand\ccoord[1]{\ncoord[0.5em,0.9em]{#1}}%
\newcommand\bcoord[1]{\ncoord[0.4em,-0.3em]{#1}}%
\newcommand\dcoord[1]{\ncoord[0.9em,1.5em]{#1}}%
\newcommand\ecoord[1]{\ncoord[0.9em,-0.3em]{#1}}%
\tikzset{
oxidation/.style={thick,red!80!black},
reduction/.style={thick,blue!80!black},
}
~
% First reaction
\[
\ce{{\ccoord{a}} Na + {\bcoord{c}} Cl -> {\ccoord{b}} Na+ + {\bcoord{d}} Cl-}
\]
\tikz[overlay,remember picture] {
\draw[oxidation,->] (a) -- ++(0,0.7em) -| (b)
node[above, near start] {Oxidation};
\draw[reduction,->] (c) -- ++(0,-0.7em) -| (d)
node[below, near start] {Reduktion};
}
\\[0.5cm] % add some extra vertical spacing
% Second reaction
\[
\ce{%
{\dcoord{a}} $\overset{\text{0}}{\text{2\,Na}}$
+{\ecoord{c}}$\overset{\text{0}}{\text{Cl$_2$}}$ ->
{\dcoord{b}} $\overset{\text{+I}}{\text{2\,Na$^+$}}$ +
{\ecoord{d}} $\overset{\text{-I}}{\text{2\,Cl$^-$}}$}
\]
\tikz[overlay,remember picture] {
\draw[oxidation,->] (a) -- ++(0,0.7em) -| (b)
node[above, near start] {Oxidation};
\draw[reduction,->] (c) -- ++(0,-0.7em) -| (d)
node[below, near start] {Reduktion};
}
\end{document}
Comments
This example was originally posted on the pgf-users mailing list.
Adding comments is currently not enabled.