2

I trying to draw a path from a node to another node using three perpendicular lines instead of two. Is there any method to do that?

My LaTeX code:

\documentclass[12pt]{report}

\usepackage{tikz} \usetikzlibrary{shapes, arrows}

\begin{document} \centering % Define block styles \tikzstyle{process} = [rectangle, draw, text width=5em, text centered] \tikzstyle{line} = [draw, -latex'] \tikzstyle{input} = [trapezium, draw, minimum width=2cm, text width=3em, trapezium left angle=120, trapezium right angle=60, text centered]

\begin{tikzpicture}[node distance=3cm, auto]
    % Place nodes
    \node [input] (input) {Image};
    \node [process, right of=input] (bin_thresh_inv) {Binary threshold and invert};
    \node [process, right of=bin_thresh_inv] (draw_border) {Draw borders};
    \node [process, above right of=draw_border] (det_vert) {Detect vertical lines};
    \node [process, below right of=draw_border] (det_hor) {Detect horizontal lines};
    \node [process, below right of=det_vert, xshift=1.5cm] (gen_mask) {Generate mask and remove lines};

    % Draw edges
    \path [line] (input) -- (bin_thresh_inv);
    \path [line] (bin_thresh_inv) -- (draw_border);
    \path [line] (draw_border) |- (det_vert);
    \path [line] (draw_border) |- (det_hor);
    \path [line] (det_hor.east) -| (gen_mask.west);
    \path [line] (det_vert.east) |- (gen_mask.west);

\end{tikzpicture}

\end{document}

Current result:

enter image description here

What I want:

enter image description here

1 Answers1

2

Add +(0.5,0) |- and -| +(0.5,0) to your path.

\documentclass[12pt]{report}

\usepackage{tikz} \usetikzlibrary{shapes, arrows}

\begin{document} \centering % Define block styles \tikzstyle{process} = [rectangle, draw, text width=5em, text centered] \tikzstyle{line} = [draw, -latex'] \tikzstyle{input} = [trapezium, draw, minimum width=2cm, text width=3em, trapezium left angle=120, trapezium right angle=60, text centered]

\begin{tikzpicture}[node distance=3cm, auto]
    % Place nodes
    \node [input] (input) {Image};
    \node [process, right of=input] (bin_thresh_inv) {Binary threshold and invert};
    \node [process, right of=bin_thresh_inv] (draw_border) {Draw borders};
    \node [process, above right of=draw_border] (det_vert) {Detect vertical lines};
    \node [process, below right of=draw_border] (det_hor) {Detect horizontal lines};
    \node [process, below right of=det_vert, xshift=1.5cm] (gen_mask) {Generate mask and remove lines};

    % Draw edges
    \path [line] (input) -- (bin_thresh_inv);
    \path [line] (bin_thresh_inv) -- (draw_border);
    \path [line] (draw_border) |- (det_vert);
    \path [line] (draw_border) |- (det_hor);
    \path [line] (det_hor.east) -|  +(0.5,0) |- (gen_mask.west);
    \path [line] (det_vert.east) -| +(0.5,0) |-(gen_mask.west);     
\end{tikzpicture}

\end{document}

enter image description here

Explanation: With have 3 node A,B and C. \path [line] (a.east) -| +(0.5,0) |- (b.west); will connect a.east with b.west by going through the coordinate (0.5,0) (red line). -| just means horizontal line and vertical line.

If we write (0.5,5) you can see that the blue line overshoots since it is higher than the node itself.

In \path [line,green] (c.north) |- +(2,2) |- (b.west); we leave north then go right passing the coordinate (+2,2). The coordinate of our node c.north point is (0,9) plus (2,2) so the line goes through (2,11) marked with x. Then goes down | and connects with b.west (green).

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{shapes, arrows} \begin{document}

\begin{tikzpicture}
    \tikzstyle{line} = [draw, -latex']

    \node[draw=black,minimum size=2cm] at (0,0) (a) {A};
    \node[draw=black,minimum size=2cm] at (4,4) (b) {B};
    \node[draw=black,minimum size=2cm] at (0,8) (c) {C};

    \path [line] (a.east) -|  +(0.5,0) |- (b.west);
    \path [line,red] (a.east) -|  +(1,0) |- (b.west);
    \path [line,green] (c.north) |-  +(2,1) |- (b.west);        


\end{tikzpicture}


\end{document}

enter image description here

Roland
  • 6,655