# How do I position pairs of arrows in TikZ to make 'harpoons'?

I wish to use left-right 'harpoons' to show a reversible reaction in a kinetic scheme. I can get part of the way, but how can I vertically shift the horizontal arrows so that I have them separated (to give harpoons) rather than overlying each another?

Or is there an altogether better way of doing this?

Using TikZ

\usepackage{tikz}
\usetikzlibrary{matrix,arrows}


Then

\begin{tikzpicture}
\matrix (m) [matrix of nodes, column sep=3em]
{A + R & AR & AR* \\};
\path[-left to, font=\scriptsize]
(m-1-1) edge node[above]{$k_{+1}$} (m-1-2);
\path[-left to,font=\scriptsize]
(m-1-2) edge node[below] {$k_{-1}$} (m-1-1);
\path[-left to,font=\scriptsize]
(m-1-2) edge node[above] {$\alpha$} (m-1-3);
\path[-left to,font=\scriptsize]
(m-1-3) edge node[below] {$\beta$} (m-1-2);
\end{tikzpicture}


Updated: Thanks to all those that responded with advice - all suggesting routes other than TikZ. These are certainly appropriate in many cases, but the reason I went with TikZ was the desire to generate more complex schemes than simple linear equations (see below). Also, a couple of points, ideally I wanted the harpoons to be a fixed length and the reactants not to be in mathmode (ie roman not italic).

I still have no response directly addressing the generation of harpoons in TikZ.

The picture above was produced with the following code:

\begin{tikzpicture}

% define matrix
\matrix (m) [matrix of nodes, column sep=3em, row sep=2em]
{ & & & AR*\\
A + R & ARb & ARc \\

% agonist binding
\path[-left to, font=\scriptsize]
(m-2-1) edge node[above]{$k_{+1}$} (m-2-2);
\path[-left to,font=\scriptsize]
(m-2-2) edge node[below] {$k_{-1}$} (m-2-1);

% cleft closure
\path[-left to,font=\scriptsize]
(m-2-2) edge node[above] {$\beta$} (m-2-3);
\path[-left to,font=\scriptsize]
(m-2-3) edge node[below] {$\alpha$} (m-2-2);

% channel opening
\path[-left to, font=\scriptsize]
(m-2-3) edge node[above, xshift=-6] {$\delta$} (m-1-4);
\path[-left to, font=\scriptsize]
(m-1-4) edge node[below, xshift=6] {$\gamma$} (m-2-3);

% desensitization
\path[-left to, font=\scriptsize]
(m-2-3) edge node[above, xshift=16] {1000 s$^{-1}$} (m-3-4);
\path[-left to, font=\scriptsize]
(m-3-4) edge node[below, xshift=-10] {10 s$^{-1}$} (m-2-3);

\end{tikzpicture}

-
–  Caramdir Feb 3 '11 at 16:28
Caramdir - thanks for the pointer. Not certain these approaches are appropriate here but I'll have a look. –  scitexter Feb 3 '11 at 16:38
Have you seen this: tex.stackexchange.com/questions/6908/harpoons-in-tikz ? –  morbusg Feb 3 '11 at 19:51

I would suggest using the chemfig package for such purposes. It has built-in commands for schemes like these which are highly customizable. What's more it provides several arrow types, one of them being harpoons for an equilibrium reaction:

\documentclass{article}
\usepackage{chemfig,siunitx}
\setcompoundsep{7em} % (not exactly) the length of the arrows
\begin{document}
\schemestart
A \+ R
\arrow{<=>[$k_{+1}$][$k_{-1}$]}
ARb
\arrow{<=>[$\alpha$][$\beta$]}
ARc
\arrow(ARc--){<=>[$\delta$][$\gamma$]}[35] AR$^*$
\schemestop
\end{document}


-
Great solution! Certainly easier to follow code than my hack with transform canvas. FYI I get ! siunitx error: "support-outdated" and Support package expl3 too old. but I will look into this... –  scitexter Dec 9 '11 at 17:29
That sounds like your TeX system isn't up to date... –  cgnieder Dec 10 '11 at 11:09
\documentclass{minimal}
\usepackage{mathtools}

\begin{document}
$A + R \xrightleftharpoons[k_{-1}]{k_{+1}} AR \xrightleftharpoons[\alpha]{\beta} AR*$
\end{document}


-

In answer to my original question (above), I found that using the transform canvas command provided the easiest way to generate rightleftharpoon-like arrows using TikZ. Thanks to Caramdir for pointing out this previous answer. Below is a simple (somewhat meaningless example) showing both horizontal and angled harpoons.

\resizebox{!}{!}{  % picture placed inside a resize box (change to values etc as per desired sizing)

\begin{tikzpicture}

\node (A) at (0,0) {A + R};
\node (B) at (1.7,0) {AR};
\node (C) at (3,1) {AR*};

\begin{scope}[every node/.style={font= \scriptsize}]

\draw[transform canvas={yshift=0.3ex},-left to] (A) -- node[above]{$k_{+1}$}  (B);
\draw[transform canvas={yshift=-0.3ex},left to-] (A) -- node[below] {$k_{-1}$} (B);

\draw[transform canvas={yshift=0.2ex, xshift=-0.05ex},-left to] (B) --  node[above, xshift=-5]{$\beta$} (C);
\draw[transform canvas={yshift=-0.32ex, xshift=0.2ex},left to-] (B) --  node[below, xshift=5]{$\alpha$} (C);

\draw[transform canvas={yshift=0.32ex, xshift=0.2ex},-left to] (B) --  node[above, xshift=15]{1000 s$^{-1}$}  (D);
\draw[transform canvas={yshift=-0.2ex, xshift=-0.05ex},left to-] (B) --  node[below, xshift=-10]{10 s$^{-1}$}  (D);

\end{scope}

\end{tikzpicture}

}


This produces:

-

At first, I thought of just using the stackrel package with the \rightleftharpoons symbol as the relation. The problem is that the \rightleftharpoons character is fixed width. Therefore, I first created a macro for typesetting a variable width right-left harpoon in TikZ:

\def\longleftrightharpoon#1{\tikz{
\draw[-left to,above=0.1em] (0,0) -- (#1,0);
\draw[-left to,below=0.1em] (#1,0) -- (0,0);
}}


The argument to that macro is the width of the harpoons. Next, I created a macro for drawing your reversible reaction using the stackrel package and our new \longleftrightharpoon macro:

\def\revreact#1#2{{
\setbox0=\hbox{$\displaystyle #1$}
\setbox1=\hbox{$\displaystyle #2$}
\dimen9=\wd0
\ifdim\wd1>\dimen9\dimen9=\wd1\fi
\,\stackrel[\box1]{\box0}{\longleftrightharpoon{\the\dimen9}}\,
}}


What's going on in there is that I first typeset the numerator and denominator to temporary boxes and then I compare the widths of the boxes to see how wide the harpoon should be.

To reproduce your example, one would simply do:

\begin{displaymath}
A + R \revreact{k_{+1}}{k_{-1}} AR \revreact{\alpha}{\beta} AR*
\end{displaymath}


which results in the following:

You may have to play with the spacing a bit to get it exactly how you want it. You may also want to reduce the size of the numerators and denominators by removing the "\displaystyle" commands from inside the \setboxes. You can also adjust the whitespace surrounding the reactions by altering the \, commands.

-

In the example below, the code for calculating the arrow positions has been factored out into a macro. The nodes can be placed at arbitrary positions, and the arrows are rotated accordingly, while keeping the distance between them constant.

\documentclass{minimal}

\usepackage{tikz,calc}       % note we use both package calc
\usetikzlibrary{calc,arrows} % and tikzlibrary calc

\newdimen{\myx}
\newdimen{\myy}
\newlength{\myxoff}
\newlength{\myyoff}

\newcommand{\reversiblearrow}[3][1]{
% Arguments: Optional arrow spacing, node name 1, node name 2

% obtain raw difference vector
\path ($(#3) - (#2)$);
\pgfgetlastxy{\myx}{\myy};

% obtain normalized difference vector
\pgfpointnormalised{\pgfpoint{\myx}{\myy}};
\pgfgetlastxy{\myx}{\myy};

% assign real TeX lengths
\setlength{\myxoff}{\myy}
\setlength{\myyoff}{\myx}

\draw[-left to,transform canvas={xshift=-#1\myxoff,yshift=#1\myyoff}]%
(#2) -- (#3);
\draw[left to-,transform canvas={xshift=#1\myxoff,yshift=-#1\myyoff}]%
(#2) -- (#3);
}

\begin{document}

\begin{tikzpicture}

\node (A) at (0in,0.25in) {A};
\node (B) at (0.5in,0in) {B};
\node (C) at (0.5in,0.5in) {C};

\reversiblearrow{A}{C}
\reversiblearrow{B}{C}

% an arrow pair with wider distance
\reversiblearrow[2]{A}{B}
\end{tikzpicture}

\end{document}


-