使用 绘制节点链tikz chains
。我想绘制一个覆盖链节点的矩形节点(或者,多个覆盖子集的矩形节点)。我正在使用tikz fit
。
不幸的是,按照我的使用方式,矩形节点被视为链的一部分。因此,绘制到矩形位置的附加连接边有点混乱。以下是 MWE:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains, fit}
\begin{document}
\begin{tikzpicture}[start chain, node distance=5mm, every node/.style={draw, on chain, join}, every join/.style=->]
\node (a) {a};
\node (b) {b};
\node (c) {c};
\node (d) {d};
\begin{scope} [start branch=numbers, every join/.style=<-]
\node (1) [on chain=going above] {1};
\node (2) [on chain=going above] {2};
\end{scope}
\node (e) {e};
\node (fit2) [draw, inner sep=2pt, fit=(a) (b) ] {};
\node (fit1) [draw, inner sep=2pt, fit=(d) (1) (e)] {};
\end{tikzpicture}
\end{document}
有和没有覆盖矩形的结果分别是
答案1
不要将最后两个节点包含在您说every node/.style=on chain
或覆盖every node
样式的范围内再次。
代码A
\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{chains, fit}
\begin{document}
\begin{tikzpicture}[node distance=5mm]
\begin{scope}[start chain, every node/.style={draw, on chain, join}, every join/.style=->]
\node (a) {a};
\node (b) {b};
\node (c) {c};
\node (d) {d};
\begin{scope} [start branch=numbers, every join/.style=<-]
\node (1) [on chain=going above] {1};
\node (2) [on chain=going above] {2};
\end{scope}
\node (e) {e};
\end{scope}
\node (fit2) [draw, inner sep=2pt, fit=(a) (b) ] {};
\node (fit1) [draw, inner sep=2pt, fit=(d) (1) (e)] {};
\end{tikzpicture}
\end{document}
代码 B
\documentclass[border=5pt, tikz]{standalone}
\usetikzlibrary{chains, fit}
\begin{document}
\begin{tikzpicture}[node distance=5mm, start chain, every node/.style={draw, on chain, join}, every join/.style=->]
\node (a) {a};
\node (b) {b};
\node (c) {c};
\node (d) {d};
\begin{scope} [start branch=numbers, every join/.style=<-]
\node (1) [on chain=going above] {1};
\node (2) [on chain=going above] {2};
\end{scope}
\node (e) {e};
\tikzset{every node/.style={draw, inner sep=+2pt}}
\node (fit2) [fit=(a) (b) ] {};
\node (fit1) [fit=(d) (1) (e)] {};
\end{tikzpicture}
\end{document}