Home > tikz pgf > Drawing a polyline between two nodes in tikz

# Drawing a polyline between two nodes in tikz

June 2Hits:11

I am a beginner with tikz and finding the following really difficult to do.

I have defined and drawn node1 and node2 in tikz. You can figure it out easily from the picture. What I intend to do is

• Draw a dashed line from (node1.south) to P1.
• Draw a dashed line from P1 to P2.
• Draw a pointed dashed line from P2 to (node2.north).
• where the point P1 is (node1.south)+(0,-y). y is a positive integer which I am free to choose depending on y-axis distance between node1 and node2.
• and I define the point P2 as the point where a horizontal left-ward line from P1 meets the vertical upward line from (node2.north).
This thing roughly accomplished in google drawing is shown.

Qrrbrbirlbel's great paths.ortho library is perfect for this. Using the library, you don't have to calculate the support points manually, but instead you can simply write

\draw [dashed, -latex] (A) |-| (B);



to get

or

\draw [dashed, -latex, hvvh/ratio=0.7] (A) |-| (B);



to get

Together with Luigi's awesome arrows.new library, which allows you to scale arrow tips without changing the line widths or resorting to decorations, you can write

\draw [dashed, -latex new, arrow head=3mm, hvvh/ratio=0.7] (A) |-| (B);



to get

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{paths.ortho, arrows.new}
\begin{document}
\begin{tikzpicture}
\node [draw] (A) {Node A};
\node [draw] (B) at (-1,-2) {Node B};
\draw [dashed, -latex new, arrow head=3mm, hvvh/ratio=0.7] (A) |-| (B);
\end{tikzpicture}
\end{document}



General points can be computed using the calc library of tikz. An expression of the form

($x!t!y$)



will find the point a fraction t along the line from x to y. Combining this with drawing directives |- and -| for "vertical then horizontal" and vice versa gives:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\node[rectangle,fill=blue!30,draw] (A) at (6,4) {Node 1};
\node[rectangle,fill=blue!30,draw] (B) at (0,0) {Node 2};
\draw[dashed,->] (A.south) |- ($(A)!.7!(B)$) -| (B.north);
\end{tikzpicture}

\end{document}



There are different ways to change the arrow. Firstly, just writing

\draw[dashed,->,>=stealth]



will give another shape. Loading the tikz library arrows gives plenty to choose between. Making the line thicker will also make the arrow more prominent, e.g. the combination

\draw[dashed,->,>=stealth,very thick]



Note that you could start your picture with \begin{tikzpicture}[>=stealth,very thick] to make all arrowheads of stealth type, and all lines very thick.

For more control over the arrow, you can use the decorations mechanism. In your case this could look like:

from the following code

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,arrows,decorations.markings}

\begin{document}

\begin{tikzpicture}[>=stealth,decoration={markings,mark=at position 1 with
{\arrow[scale=3]{>}}}]
\node[rectangle,fill=blue!30,draw] (A) at (6,4) {Node 1};
\node[rectangle,fill=blue!30,draw] (B) at (0,0) {Node 2};
\draw[dashed,postaction={decorate}]
(A.south) |- ($(A)!.7!(B)$) -| (B.north);
\end{tikzpicture}

\end{document}



See the pgf manual for further details and constructions. Another illustration of arrow tips via decorations may be found at TikZ: Large arrow tips at the end of smooth curves.

Tags:tikz pgf

## Related Articles

• ### Drawing a polyline between two nodes in tikzJune 2

I am a beginner with tikz and finding the following really difficult to do. I have defined and drawn node1 and node2 in tikz. You can figure it out easily from the picture. What I intend to do is Draw a dashed line from (node1.south) to P1. Draw a da

• ### How to draw saturation symbol inside a node in TikZAugust 1

I'm working on a block diagram using TikZ. I'd like to create a symbol like below, which means I have to draw 5 lines inside a node and write a letter in the upper-right corner. What's the best way to achieve what I need? Any hints appreciated. -----

• ### draw round/rectangular bracket embracing nodes in tikzSeptember 30

I know how to draw a curly bracket with the following code: \draw[decorate,decoration={brace,amplitude=5},-] (0.8,-0.75) -- (0.8,0.75); But now I want to draw a round bracket, or a rectangular one. Can anyone tell how can I do this? Is it possible to

• ### Draw ellipsis (three dots) between nodes in tikzJune 1

I am beginning to learn tikz to draw a simple graph. I would like to represent the idea that there are N nodes by drawing something like this: How can I draw an ellipsis: ... between the two nodes? Here is the code I used for the above: \documentclas

• ### Draw two lines between two nodes with tikzJune 22

I have two nodes \node (A) {A}; \node [below=of A] (B) {B}; I can draw a line between them with \draw (A) -- (B); But I need two lines between them. If I'm using \draw (A) -- (B); \draw (B) -- (A); it will draw the two lines on top of each other. Can

• ### Tikz - How to Draw Boxes Around Set of NodesJanuary 13

How to draw the boxes as shown in the attached image? I could only manage to draw the chart but could not highlight the desired node / nodes with a rectangle box. Preferably dotted. I could not draw dotted in MS paint. \documentclass{article} \usepac

• ### Draw edges and paths in the background of nodes in TikZMay 14

Is it possible to draw edges or paths in the background of nodes independently of whether they are constructed before or after the nodes are defined? In the following example, the \draw instruction comes after the nodes are declared and so the path f

• ### Draw a shape around a set of nodes using TikZ September 1

I'm trying to draw a boundary around a convex set of circular nodes in TikZ. The aim is to have it padded by 1cm, with an arc at the corners between segments, like this: I currently have the following code: \documentclass{article} \usepackage{tikz} \

• ### Draw an arc between 2 nodes and label it in TikZSeptember 2

I have already drawn two ellipses l1 and l2, l2 is on the left below l1: \begin{tikzpicture} \node (l1) [ellipse, draw=black, fill=white!20, text=black, scale=0.8, text centered]{ $l_1$}; \node (l2) [ellipse, draw=black, fill=white!20, text=black, sc

• ### How to nest a graph within a node in TikZ and draw edges between the graphs?September 7

I'm trying to draw a graph and have a separate graph within one of the outer nodes. I seen this question, but I don't understand how the matrix nodes will help me. I would also like to draw edges between the outer nodes to the inner nodes. Could some

• ### How to draw complex nodes in tikz?August 16

I know how to draw automaton in tikz. But how to use complex nodes in that? I want draw something like this in tikz: --------------Solutions------------- Probably you can do it with the matrix library: \documentclass[parskip]{scrartcl} \usepackage[ma

• ### Drawing a vertical line between two nodes in TikZ December 18

I have the following tikz code % compilation command: pdflatex --jobname=Diag-f1 Diag.tex \documentclass{book} \usepackage{tikz} \pgfrealjobname{Diag} \begin{document} \beginpgfgraphicnamed{Diag-f1} \begin{tikzpicture}[node distance=3em] \node(G)[rec

• ### Drawing iterations of a recursive structure in TikZ / using node names defined in a loopMay 7

This is my first time using TikZ, and I'm trying to draw something related to the Hilbert space-filling curve, based on a recent popular article (HTML, PDF). Specifically, I'm trying to draw the first few iterations of the curve, with nodes labelled

• ### Custom draws in matrix nodes in tikz v3 with referencingJuly 23

With tikz v3 the matrix behavior has changed slightly. The great example at http://www.texample.net/tikz/examples/BER-measurement/ doesn't seem to compile any longer. The problem is that the default naming of matrix nodes as m-1-1 etc. is now overrid

• ### How to draw the following GERT network node diagram using tikzDecember 8

How to draw the following nodes in tikz, Kindly help me. --------------Solutions------------- Some code to start with. It uses a semicircle shape which is completed according the symbol you want. \documentclass[tikz,border=2mm]{standalone} \usetikzli

• ### Draw arrows between nodes with tikzJune 23

I have drawn 4 nodes with \documentclass[tikz,border=5pt]{standalone} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[node distance=2cm] % nodes \node [draw] (A) {A}; \node [draw, right=of A] (B) {B}; \node [draw, right=of B] (C) {C

• ### drawing oddly shaped nodes to contain existing nodes in tikzOctober 25

I have a somewhat complex figure in tikz. You'll notice there are two colors (they look red and green to me, but I'm told they are distinguishable to color-blind people: if you're color blind and they aren't different, please tell me). I would like t

• ### Relative positioning of nodes in TikZApril 13

Consider this simple example: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture}[scale=1.5] % Draw axes \draw [<->,thick] (0,2.2) node (yaxis) [above] {$t$} |- (2.2,0) node (xaxis) [right] {$s$}; % Draw triangle's legs \d

• ### How to draw the border of a node using late optionsMay 20

I want to create a series of rectangles, each with a different shade. The shade varies from white to black. I want to make the white (first) rectangle visible by drawing its border. My first step is to draw all the rectangles, without any conditional

• ### Using scalable sizes for rectangles, circles and nodes in TikZ?September 27

How do you define the size of a rectangle, circle or node in TikZ to be scalable, like when you position objects using (1, 2) and then apply scale=2? What I'm looking for is to be able to scale the objects like circles and boxes along with the coordi