使用 Tikz \path [line] 从节点到节点绘制三条垂直线?

使用 Tikz \path [line] 从节点到节点绘制三条垂直线?

我尝试使用三条垂直线(而不是两条)绘制从一个节点到另一个节点的路径。有什么方法可以做到这一点吗?

我的 LaTeX 代码:

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

目前结果:

在此处输入图片描述

我想要的是:

在此处输入图片描述

答案1

添加+(0.5,0) |--| +(0.5,0)到您的路径。

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

在此处输入图片描述

解释:有 3 个节点 A、B 和 C。 \path [line] (a.east) -| +(0.5,0) |- (b.west);将通过坐标(红线)连接。a.east也就是水平线和垂直线。b.west(0.5,0)-|

如果我们写的话,(0.5,5)你会看到蓝线超出范围,因为它高于节点本身。

我们\path [line,green] (c.north) |- +(2,2) |- (b.west);从北边出发,然后向右经过坐标(+2,2)。我们的节点 c.north 点的坐标为(0,9)(2,2),因此该线经过(2,11)标记为 x 的点。然后向下并与(绿色)|连接。b.west

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

在此处输入图片描述

相关内容