如何在 tikz 中建立圍繞節點的非矩形邊框?

如何在 tikz 中建立圍繞節點的非矩形邊框?

我有以下 MWE。

我想畫一個邊框沒有包括 $y_3$ (或 .tex 檔案中的 s3)——因此它將是一個矩形,其左上角已更改,以便繞過 s3。有沒有辦法創建這樣一個邊界,基本上就是一個圍繞一組節點的矩形多邊形?

(編輯:我試圖使用 tikz 文件中的最後一個命令來執行此操作。)

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{fit,chains}

\begin{document}

\begin{tikzpicture}[node distance=2cm]

  \node(s1) {$y_1$};
  \node(s2) [right of = s1] {$y_2$};
  \node(s3) [right of = s2]{$y_{3}$};
  \node(s4) [right of = s3]{$y_4$};
  \node(s5) [right of = s4]{$y_5$};

\draw [->] (s1) -- (s2) ;
\draw [->] (s2) -- (s3) ;
\draw [->] (s3) -- (s4) ;
\draw [->] (s4) -- (s5) ;


  \node(x1) [below of = s1]{$x_1$};
  \node(x2) [right of = x1] {$X_2$};
  \node(x3) [right of = x2] {$X_3$};
  \node(x4) [right of = x3] {$X_4$};
  \node(x5) [right of = x4] {$X_5$};

\draw [->] (s1) -- (x1) ;
\draw [->] (s2) -- (x2) ;
\draw [->] (s3) -- (x3) ;
\draw [->] (s4) -- (x4) ;
\draw [->] (s5) -- (x5) ;

\node[rectangle,draw=red, fit=(x3) (x4) (x5) (s4) (s5),inner sep=3mm,line width=1mm](rect2) {};

\end{tikzpicture}
\end{document}

答案1

node如果您接受非自動繪製的線而不是a ...

\documnentclass{article}

\usepackage{tikz}

\usetikzlibrary{fit,chains, calc}

\begin{document}

\begin{tikzpicture}[node distance=2cm]

  \node(s1) {$y_1$};
  \node(s2) [right of = s1] {$y_2$};
  \node(s3) [right of = s2]{$y_{3}$};
  \node(s4) [right of = s3]{$y_4$};
  \node(s5) [right of = s4]{$y_5$};

\draw [->] (s1) -- (s2) ;
\draw [->] (s2) -- (s3) ;
\draw [->] (s3) -- (s4) ;
\draw [->] (s4) -- (s5) ;


  \node(x1) [below of = s1]{$x_1$};
  \node(x2) [right of = x1] {$X_2$};
  \node(x3) [right of = x2] {$X_3$};
  \node(x4) [right of = x3] {$X_4$};
  \node(x5) [right of = x4] {$X_5$};

\draw [->] (s1) -- (x1) ;
\draw [->] (s2) -- (x2) ;
\draw [->] (s3) -- (x3) ;
\draw [->] (s4) -- (x4) ;
\draw [->] (s5) -- (x5) ;

\node[rectangle,draw=red, fit=(x3) (x4) (x5) (s4) (s5),inner sep=3mm,line width=1mm](rect2) {};

\draw[blue, line width=1mm] (x3.south west)-|(s5.north east) --($(s3.north)!0.5!(s4.north)$)|-($(s3.west)!0.5!(x3.west)$)--cycle;
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容