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?


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:



\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};



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).


A way to build a parallel to (a)--(b) at a distance 1cm:

\draw ($(a)!0cm!(b)!-1cm!90:(b)$) -- ($(b)!0cm!(a)!1cm!90:(a)$);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.