# A line parallel to an edge in a TikZ picture

I have a graph in TikZ built using code like the following

\node[...] (1) at (0,0) {1};

\node[...] (2) at (1,1) {2}
edge (1);


I would like to add a short line (with an arrow) parallel to the edge between 1 and 2, at some distance from the edge (and attach a label to the short line). Is there an easy way of doing it, without calculating coordinates?

• I think TikZ parallel Edges between Nodes might help you. – Claudio Fiandrino Mar 31 '13 at 16:04
• Thanks. Is there a reference for understanding decorations library? I couldn't find any information in TikZ manual. Also what is \tikzset and why for examplenot use \tikzstyle instead? – passerby51 Apr 1 '13 at 1:37
• Yes, on the pgfmanual you have an introduction in 21 Decorated Paths then the library is explained in detail in 30 Decoration Library. The macro \tikzset is the recommended way to define styles while \tikzstyle is deprecated, as per Should \tikzset or \tikzstyle be used to define TikZ styles?. – Claudio Fiandrino Apr 1 '13 at 12:33

You can use a decoration, like in the answers pointed by Claudio Fiandrino, and this can be specially useful if you have several arrows like this in your drawing.

A different approach, which can be useful for single particular cases, could be the following:

\usetikzlibrary{calc}

\begin{tikzpicture}

\node[] (1) at (0,0) {1};
\node[] (2) at (1,1) {2}
edge (1);

\draw[->] ($(1)!0.3!(2)!1mm!90:(2)$) -- ($(1)!0.7!(2)!1mm!90:(2)$)
node[midway,sloped,above] {\tiny label};

\end{tikzpicture}


The syntax used for this is called "interpolated coordinates". In the above code you can tweak the amounts 0.3 and 0.7 (which are the fraction of the segment length at which the arrow will start and end) and 1mm (which is the distance between the parallel arrow and the main segment). You can also replace 90 by -90 if you want the parallel arrow below the original segment (and in this case, of course, you should use below option for the label).