# Customize arrow path tikz

I want to connect two nodes with an arrow, but I want the arrow to follow a "customized" path.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,mindmap,trees,automata}

\begin{document}
\begin{tikzpicture}
\node[state,initial,initial text=G] (1)   {$1$};
\node[state] (2) [right=of 1] {$2$};

\draw[->] (1) edge  node[sloped, above] {a} (2);
\end{tikzpicture}
\end{document}


I want the arrow to be like this:

Not the prettiest drawing but I hope you understand what I want. Thank you very much in advance! :)

• While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This is especially important for tikz as there are numerous libraries. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Jan 20 '16 at 8:58
• Thank you for the comment, I have now included all of my code for this :) – Maggie Jan 20 '16 at 9:04

There are several ways of solving this, here is one using the |- path specification (meaning go first vertically, then horizontally, to the next coordinate) and one relative coordinate.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,automata}

\begin{document}
\begin{tikzpicture}
\node[state,initial,initial text=G] (1)   {$1$};
\node[state] (2) [right=of 1] {$2$};
\draw[->,rounded corners] (1) |- node[pos=0.75,fill=white,inner sep=2pt]{a} ++(1,1) |- (2);
\end{tikzpicture}
\end{document}

• Thank you very much for your help! :) Is there also a way to make the edges rounded? – Maggie Jan 20 '16 at 19:12
• @Maggie Sure, add rounded corners to the \draw options, see updated answer. You can also specify a radius with rounded corners=<radius>, e.g. rounded corners=5pt. Note that with a large radius there were some artifacts near the edge of the a node, which is why I also increased the inner sep a bit. – Torbjørn T. Jan 20 '16 at 21:12

One could solve it - rather unelegant - with control points inbetween. I don't know why the last line is not perfectly horizontal, though.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,automata}

\begin{document}
\begin{tikzpicture}
\node[state,initial,initial text=G] (1) {$1$};
\node (ctrl1) [above=of 1, anchor=north] {};
\node (ctrl2) [right=of ctrl1, anchor=east] {};
\node (ctrl3) [below=of ctrl2, anchor=north] {};
\node[state] (2) [right=of 1] {$2$};
\draw (1) -- (ctrl1.south) -- node [fill=white] {a} (ctrl2.south) -- (ctrl3.south) -- (2);
\end{tikzpicture}
\end{document}


• because you go from ctrl3.south to 2.west, I think. Replace \node(ctrl3) by \coordinate(ctrl3) and ctrl3.south by ctrl3 – pluton Jan 20 '16 at 21:26