如何绘制带箭头的正交线以避免与现有矩形发生碰撞?

如何绘制带箭头的正交线以避免与现有矩形发生碰撞?

我尝试了以下方法,几乎​​可以工作,但看起来很丑:

  1. 一转弯线就断了。

  2. 它实际上并不是完美的水平和垂直,只是我的近似值。

USB 和 Comp 之间的线不是水平的。

我怎样才能让它更漂亮?我试图从这个例子中学习,但我缺乏良好的 tikz 基础来适应我的:正交路径布线

它看起来是这样的:

在此处输入图片描述

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, arrows, fit,calc}

\begin{document}
\tikzset{computer/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 5em, line width=1pt}}
\tikzset{UHD_int/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 7em, line width=1pt}}
\tikzset{switch_int/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 7em, line width=1pt}}
\tikzset{display/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 8em, line width=1pt}}
\tikzset{touchPanel/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 5em, line width=1pt}}
\tikzset{mouseKeyboard/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 5em, line width=1pt}}

\tikzstyle{line}    = [ draw, -triangle 45 ]

\begin{tikzpicture}
  \node[computer] (first) {Comp. 1};
  \node[computer,below=of first] (second) {Comp. 2};
  \node[computer,below=of second] (third) {Comp. 3};
  \node[computer,below=of third] (fourth) {Comp. 4};
  \node[computer,below=of fourth] (fifth) {Comp. 5};
  \node[computer,below=of fifth] (sixth) {Comp. 6};
  \node[computer,below=of sixth] (seventh) {Comp. 7};

  \node[UHD_int, right=5cm of first] (first_video_in) {HDMI 1};
  \node[UHD_int,below=of first_video_in] (second_video_in) {HDMI 2};
  \node[UHD_int,below=of second_video_in] (third_video_in) {HDMI 3};
  \node[UHD_int,below=of third_video_in] (fourth_video_in) {HDMI 4};
  \node[UHD_int,below=of fourth_video_in] (fifth_video_in) {DisplayPort 5};
  \node[UHD_int,below=of fifth_video_in] (sixth_video_in) {DisplayPort 6};
  \node[UHD_int,below=of sixth_video_in] (seventh_video_in) {RGB/VGA 7};

  \node[UHD_int, below=of seventh_video_in] (LAN) {LAN};
  \node[touchPanel, below=1.5cm of LAN] (touchPanel) {Touch Panel Controller};
  \node[UHD_int, above=of first_video_in] (HDMI_out) {HDMI out};

  \node (UHD) [above=0.6cm of first_video_in] {UHD};
  \node [draw=black!50, fit={(UHD) (HDMI_out) (first_video_in) (second_video_in)
      (third_video_in) (fourth_video_in) (fifth_video_in) (sixth_video_in) (seventh_video_in) (LAN)}] {};

  \node[display, right=2cm of HDMI_out] (display) {big screen};
  \draw[->] (HDMI_out) -- (display);

  \node[switch_int, left=5cm of first] (first_usb) {USB 1};
  \node[switch_int,below=of first_usb] (second_usb) {USB 2};
  \node[switch_int,below=of second_usb] (third_usb) {USB 3};
  \node[switch_int,below=of third_usb] (fourth_usb) {USB 4};
  \node[switch_int,below=of fourth_usb] (fifth_usb) {USB 5};
  \node[switch_int,below=of fifth_usb] (sixth_usb) {USB 6};
  \node[switch_int,below=of sixth_usb] (seventh_usb) {USB 7};

  \node[switch_int, below=of seventh_usb] (USB_mouse/keyboard) {USB 2.0};
  \node[mouseKeyboard, below=1.5cm of USB_mouse/keyboard] (mouseKeyboard) {Operator mouse \& keyboard};
  \node[switch_int, above=of first_usb] (touch_panel_control) {RS-232};

  \node (Switch) [above=0.6cm of first_usb] {Switch};
  \node [draw=black!50, fit={(Switch) (touch_panel_control) (first_usb) (second_usb)
      (third_usb) (fourth_usb) (fifth_usb) (sixth_usb) (seventh_usb) (USB_mouse/keyboard)}] {};

  \draw[->] (first) -- (first_video_in);
  \draw[->] (first_usb) -- (first);
  \draw[->] (second) -- (second_video_in);
  \draw[->] (second_usb) -- (second);
  \draw[->] (third) -- (third_video_in);
  \draw[->] (third_usb) -- (third);
  \draw[->] (fourth) -- (fourth_video_in);
  \draw[->] (fourth_usb) -- (fourth);
  \draw[->] (fifth) -- (fifth_video_in);
  \draw[->] (fifth_usb) -- (fifth);
  \draw[->] (sixth) -- (sixth_video_in);
  \draw[->] (sixth_usb) -- (sixth);
  \draw[->] (seventh) -- (seventh_video_in);
  \draw[->] (seventh_usb) -- (seventh);

  \draw[->] (mouseKeyboard) -- (USB_mouse/keyboard);
  \draw[->] (touchPanel) -- (LAN);

  \node[label] at (-3.5,0.3)  {muse/keyboard in};
  \node[label] at (3.1,0.3)  {video out};
\node [below left=1.7cm of mouseKeyboard] (belowMouseKeyboard) {};
\node [left=2.25cm of touch_panel_control] (leftRS232) {};
\node [below= of touchPanel] (belowTouchPanel) {};
\path [line] (touchPanel.south) -- (belowTouchPanel) -- (belowMouseKeyboard) -- (leftRS232) -- (touch_panel_control);

\end{tikzpicture}
\end{document}

答案1

这只是您的代码的修改版本,没有包含任何重大变化。

\documentclass[tikz,margin=3]{standalone}
\usetikzlibrary{positioning, arrows, fit,calc}

\begin{document}
\tikzset{computer/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 5em, line width=1pt,minimum height=.7cm}}
\tikzset{UHD_int/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 7em, line width=1pt,minimum height=.7cm}}
\tikzset{switch_int/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 7em, line width=1pt,minimum height=.7cm}}
\tikzset{display/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 8em, line width=1pt,minimum height=.7cm}}
\tikzset{touchPanel/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 5em, line width=1pt,minimum height=.7cm}}
\tikzset{mouseKeyboard/.style={shape=rectangle, draw, node distance=-1pt, minimum width = 5em, line width=1pt,minimum height=.7cm}}

\begin{tikzpicture}
  \node[computer] (first) {Comp. 1};
  \node[computer,below=of first] (second) {Comp. 2};
  \node[computer,below=of second] (third) {Comp. 3};
  \node[computer,below=of third] (fourth) {Comp. 4};
  \node[computer,below=of fourth] (fifth) {Comp. 5};
  \node[computer,below=of fifth] (sixth) {Comp. 6};
  \node[computer,below=of sixth] (seventh) {Comp. 7};

  \node[UHD_int, right=5cm of first] (first_video_in) {HDMI 1};
  \node[UHD_int,below=of first_video_in] (second_video_in) {HDMI 2};
  \node[UHD_int,below=of second_video_in] (third_video_in) {HDMI 3};
  \node[UHD_int,below=of third_video_in] (fourth_video_in) {HDMI 4};
  \node[UHD_int,below=of fourth_video_in] (fifth_video_in) {DisplayPort 5};
  \node[UHD_int,below=of fifth_video_in] (sixth_video_in) {DisplayPort 6};
  \node[UHD_int,below=of sixth_video_in] (seventh_video_in) {RGB/VGA 7};

  \node[UHD_int, below=of seventh_video_in] (LAN) {LAN};
  \node[touchPanel, below=1.5cm of LAN] (touchPanel) {Touch Panel Controller};
  \node[UHD_int, above=of first_video_in] (HDMI_out) {HDMI out};

  \node (UHD) [above=0pt of HDMI_out] {UHD};
  \node [draw=black!50, fit={(UHD) (HDMI_out) (first_video_in) (second_video_in)
      (third_video_in) (fourth_video_in) (fifth_video_in) (sixth_video_in) (seventh_video_in) (LAN)}] {};

  \node[display, right=2cm of HDMI_out] (display) {big screen};
  \draw[->] (HDMI_out) -- (display);

  \node[switch_int, left=5cm of first] (first_usb) {USB 1};
  \node[switch_int,below=of first_usb] (second_usb) {USB 2};
  \node[switch_int,below=of second_usb] (third_usb) {USB 3};
  \node[switch_int,below=of third_usb] (fourth_usb) {USB 4};
  \node[switch_int,below=of fourth_usb] (fifth_usb) {USB 5};
  \node[switch_int,below=of fifth_usb] (sixth_usb) {USB 6};
  \node[switch_int,below=of sixth_usb] (seventh_usb) {USB 7};

  \node[switch_int, below=of seventh_usb] (USB_mouse/keyboard) {USB 2.0};
  \node[mouseKeyboard, below=1.5cm of USB_mouse/keyboard] (mouseKeyboard) {Operator mouse \& keyboard};
  \node[switch_int, above=of first_usb] (touch_panel_control) {RS-232};

  \node (Switch) [above=0pt of touch_panel_control] {Switch};
  \node [draw=black!50, fit={(Switch) (touch_panel_control) (first_usb) (second_usb)
      (third_usb) (fourth_usb) (fifth_usb) (sixth_usb) (seventh_usb) (USB_mouse/keyboard)}] {};

  \draw[->] (first) -- (first_video_in);
  \draw[->] (first_usb) -- (first);
  \draw[->] (second) -- (second_video_in);
  \draw[->] (second_usb) -- (second);
  \draw[->] (third) -- (third_video_in);
  \draw[->] (third_usb) -- (third);
  \draw[->] (fourth) -- (fourth_video_in);
  \draw[->] (fourth_usb) -- (fourth);
  \draw[->] (fifth) -- (fifth_video_in);
  \draw[->] (fifth_usb) -- (fifth);
  \draw[->] (sixth) -- (sixth_video_in);
  \draw[->] (sixth_usb) -- (sixth);
  \draw[->] (seventh) -- (seventh_video_in);
  \draw[->] (seventh_usb) -- (seventh);

  \draw[->] (mouseKeyboard) -- (USB_mouse/keyboard);
  \draw[->] (touchPanel) -- (LAN);

  \node[label] at (-3.5,0.3)  {muse/keyboard in};
  \node[label] at (3.1,0.3)  {video out};
\node [below left=1.7cm of mouseKeyboard] (belowMouseKeyboard) {};
\node [left=2.25cm of touch_panel_control] (leftRS232) {};
\node [below= of touchPanel] (belowTouchPanel) {};
%\path [line] (touchPanel.south) -- (belowTouchPanel) -- (belowMouseKeyboard) -- (leftRS232) -- (touch_panel_control);

\draw[-triangle 45,very thick] 
    (touchPanel.south) |- ([yshift=-1.5cm]mouseKeyboard.south)
        -| ([xshift=-1cm]mouseKeyboard.west)
        |- (touch_panel_control);

\end{tikzpicture}
\end{document}

在此处输入图片描述

我做了什么:

  • 为每个节点设置minimum height。高度不一致会导致两列错位。
  • 删除断线并用具有一些|-和的路径替换它-|

相关内容