我想用 tikz 创建一个如下所示的流程图:
-------------------------------
| wide node |
-------------------------------
|
-------------------------------
| wide node |
-------------------------------
|
-------------------------
| | |
------ ------ ------
|sub1| |sub2| |sub3|
------ ------ ------
| | |
-----------------------
|
-------------------------------
| wide node |
-------------------------------
看起来像是一个非常基本的流程图。我尝试了很多方法来连接箭头并使子节点与其他节点一样宽,但我无法让它工作,我当前的代码如下所示:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,arrows,decorations.pathmorphing,backgrounds,fit,positioning,
shapes.symbols,chains}
\begin{document}
\tikzstyle{block} = [rectangle, draw=black, thick, fill=white, text width=8em,
text centered, minimum height=4em]
\tikzstyle{dummyblock} = [rectangle]
\tikzstyle{line} = [draw, -latex']
\begin{center}
\begin{tikzpicture}[node distance=3.5cm]
\node [block] (A) {A};
\node [block,below of= A] (B) {B};
\node [dummyblock,below of=B] (BB) {};
\node [block, below of = BB] (D) {D};
\node [block, left of=D] (C) {C};
\node [block, right of=D] (E) {E};
\node [block, below of=D] (F) {F};
\path [line] (A.south) -| (B.north);
\path [line] (B.south) -| (BB.north);
\path [line] (BB.south) -| (C);
\path [line] (BB.south) -| (D);
\path [line] (BB.south) -| (E);
\path [line] (C.south) -| (F.north);
\path [line] (D.south) -| (F.north);
\path [line] (E.south) -| (F.north);
\end{tikzpicture}\end{center}
\end{document}
有人知道如何解决这个问题吗?任何帮助都将不胜感激!
答案1
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,arrows,decorations.pathmorphing,backgrounds,
fit,positioning,shapes.symbols,chains}
\tikzstyle{block} = [rectangle, draw=black, thick, fill=white, text width=8em,
text centered, minimum height=4em]
\tikzstyle{dummyblock} = [rectangle]
\tikzstyle{line} = [draw, -latex']
\begin{document}
\begin{tikzpicture}[node distance=3.5cm]
\node [block] (A) {A};
\node [block,below =of A] (B) {B};
\coordinate [below = of B] (BB) {};
\node [block, below = of BB] (D) {D};
\node [block, left = of D] (C) {C};
\node [block, right = of D] (E) {E};
\coordinate[below = of D] (fn);
\node [block, below = of fn] (F) {F};
\path [line] (A) -- (B);
\draw (B) -- (BB);
\path [line] (BB) -| (C);
\path [line] (BB) -- (D);
\path [line] (BB) -| (E);
\draw (C) |- (fn);
\draw (D) |- (fn);
\draw (E) |- (fn);
\path[line] (fn) -- (F);
\end{tikzpicture}
\end{document}
答案2
Percusse,非常感谢你的帮助!我在最终解决方案中结合了以上所有内容:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,fit}
\tikzstyle{block} = [rectangle, draw=black, thick, fill=white, text width=8em,
text centered, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\begin{document}
\begin{tikzpicture}[node distance=0.5cm]
\node [block] (D) {D};
\node [block, left = of D] (C) {C};
\node [block, right = of D] (E) {E};
\coordinate[below = of D] (FF);
\node [ block, fit={(C) (D) (E)},label=center:F, below = of FF] (F) {};
\coordinate [above = of D] (BB) {};
\node [ block, fit={(C) (D) (E)},label=center:B, above = of BB] (B) {};
\node [ block, fit={(C) (D) (E)},label=center:A, above = of B] (A) {};
\path [line] (A) -- (B);
\draw (B) -- (BB);
\path [line] (BB) -| (C);
\path [line] (BB) -- (D);
\path [line] (BB) -| (E);
\draw (C) |- (FF);
\draw (D) |- (FF);
\draw (E) |- (FF);
\path[line] (FF) -- (F);
\end{tikzpicture}
\end{document}
顺便说一下,由于某种原因,我的 linux texlive latex 发行版出现错误(我的 windows miktex 发行版没有出现错误):
\node [ block, fit={(C) (D) (E)},label=center:A, above = of B] (A) {};
可以通过将此行替换为来解决
\node [ block, fit={(C) (D) (E)}, above = of B] (A) {A};
答案3
通过结合以上所有建议,它几乎可以发挥作用:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,arrows}
\tikzstyle{line} = [draw, -latex']
\begin{document}
\begin{tikzpicture}[node distance=0.2cm,mynode/.style={outer sep=0pt, draw}]
\node[mynode] (foo) {foo};
\node[mynode] (bar) [right=of foo] {bar};
\node[mynode] (bar2) [right=of bar] {bar2};
\coordinate[below = of bar] (cbar);
\node [ mynode,
inner sep=0pt,
yshift=-1cm,
fit={(foo) (bar) (bar2)},label=center:foobar
] (foobar) {};
\draw (foo.south) |- (cbar);
\draw (bar.south) |- (cbar);
\draw (bar2.south) |- (cbar);
\path[line] (cbar) -- (foobar.north);
\end{tikzpicture}
\end{document}
只是由于某种原因,箭头没有从三个节点下方的坐标直接绘制到更宽的节点......有人知道如何解决这个问题吗?