我想用 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}
只是由於某種原因,箭頭沒有從三個節點下方的座標直接繪製到更寬的節點......有人知道如何解決這個問題嗎?