# How to add other shapes on a arrow in tikz?

I have an arrow between 2 coordinates

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node[fill=blue,circle,text width=3cm]   (first) at (1,1) {};
\node[fill=purple,circle,text width=3cm] (third) at (1,9) {};
\draw [->] (first) -- (third);
\end{tikzpicture}
\end{document}


How can I change the arrow to something like this, I want to add shapes on it, which can contain some text

## edit

what if the arrow is on a curve?

-
No need of complex things: \draw[->] (0,0)--(0.5,0)node[draw,fill=white]{A}--(1.5,0)node[draw,fill=white]{A}--(2.5,0)‌​node[draw,fill=white]{A}--(3,0); then you can add width, height as you like. –  Claudio Fiandrino Feb 20 '13 at 14:33

You can draw nodes on top of a path using the pos=x option, where x is a number between 0 (which represents the start of the path) and 1 (which represents the end). In your example:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
my box/.style = {rectangle, draw=black, fill=white, minimum width=2.5em,
}
}
\begin{tikzpicture}
\node[fill=blue,circle,text width=3cm] (first) at   (1,1) {};
\node[fill=purple,circle,text width=3cm] (third) at (9,1) {};
\draw [->] (first) -- (third)
node[pos=0.25, my box] {A}
node[pos=0.5,  my box] {B}
node[pos=0.75, my box] {C};
\end{tikzpicture}
\end{document}


This solution has the advantage that it works easily for non-horizontal or vertical paths too. Also, if you add sloped option in my box/.style this will cause the A, B, C boxes use the same slope than the arrow line:

\tikzset{
my box/.style = {rectangle, draw=black, fill=white, minimum width=2em, sloped,
}
}

\begin{tikzpicture}
\node[fill=blue,circle,text width=1cm] (first) at   (1,1) {};
\node[fill=purple,circle,text width=1cm] (third) at (7,-3) {};
\draw [-latex] (first) -- (third)
node[pos=0.35, my box] {A}
node[pos=0.5,  my box] {B}
node[pos=0.65, my box] {C};
\end{tikzpicture}


# Update

Answering a question of the OP in a comment, the above works for curved paths as long as the path is specfied using the .. syntax, and including the Bezier control points. For example:

\tikzset{
my box/.style = {rectangle, draw=black, fill=white, minimum width=2em, sloped,
}
}

\begin{tikzpicture}
\node[fill=blue,circle,text width=1cm] (first) at   (1,1) {};
\node[fill=purple,circle,text width=1cm] (third) at (7,-3) {};
\draw [-latex] (first) .. controls (+5,0) and +(-5,0) .. (third)
node[pos=0.2, my box] {A}
node[pos=0.5, my box] {B}
node[pos=0.8, my box] {C};
\end{tikzpicture}


However, it does not work with to syntax, which would be more convenient: Update: to syntax is also supported as long as the nodes are put before the final coordinate (thanks to mwibrow for the hint!), so the following also works:

\tikzset{
my box/.style = {rectangle, draw=black, fill=white, minimum width=2em, sloped,
}
}

\begin{tikzpicture}
\node[fill=blue,circle,text width=1cm] (first) at   (1,1) {};
\node[fill=purple,circle,text width=1cm] (third) at (7,-3) {};
\draw [-latex] (first) to[out=0, in=180]
node[pos=0.3, my box] {A}
node[pos=0.5, my box] {B}
node[pos=0.7, my box] {C}
(third);
\end{tikzpicture}


-
how to make it work for curved paths? –  user494461 Feb 20 '13 at 15:09
thanks...where can I find more info on how to use controls and bezier to correctly draw my curve ? –  user494461 Feb 20 '13 at 15:25
@user494461 You can read Wikipedia about the general idea of Bezier cuvres. Tikz syntax is (P0) .. controls (P1) and (P2) .. (P3). This defines a curve which starts at P0, and ends at P3, being the starting of the curve tangent to the line P0--P1 and the end of the curve tangent to P2--P3. You can think of the control points as "magnets" which "pull" the curve.. You can specify the coordinates of control points P1 and P2 relative of those of P0 and P3, respectively, by puting + in fromt of them, as I did in the example of my answer. –  JLDiaz Feb 20 '13 at 15:40
For reasons I can't recall, nodes on to paths must go before the final coordinate. So if you put the three nodes before (third) the nodes are positioned correctly. –  Mark Wibrow Feb 20 '13 at 15:53
@mwibrow Thanks! I've updated the answer –  JLDiaz Feb 20 '13 at 16:08