我有以下 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
您接受非自动绘制的线...
\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}