:)
我正在尝试创建一个非常简单的流程图,tikzpicture
但遇到了麻烦。
我的代码:
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em]
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (init) {Begin};
\node [decision, below of=init] (hasSession) {Has SessionID?};
\node [block,left of=hasSession, node distance=5cm] (pSession) {Persist Session};
\node [block,below of=hasSession, node distance=5cm] (pVisit) {Persist Page Visit};
\node [block,below of=pVisit] (end) {End};
% Draw edges
\path [line] (init) -- (hasSession);
\path [line] (hasSession) -| node [near start] {no} (pSession);
\path [line] (pVisit) -- (end);
\end{tikzpicture}
这使得我得到以下图表
一个明显的问题是“持久会话”上的箭头。此外,如果我添加以下行:
\path [line] (pSession) -- (pVisit);
它给出了除以零的错误。
由于我需要使用更多节点和边来增强流程图,因此关于这两个问题以及进一步的提示,您有什么线索吗?
谢谢!
答案1
问题在于您使用-|
而不是--
。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric,positioning,arrows}
\begin{document}
\tikzset{decision/.style={diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt},
block/.style={rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em},
line/.style={draw, -latex'},
cloud/.style={draw, ellipse,fill=red!20, node distance=3cm,
minimum height=2em}}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (init) {Begin};
\node [decision, below of=init] (hasSession) {Has SessionID?};
\node [block,left of=hasSession, node distance=5cm] (pSession) {Persist Session};
\node [block,below of=hasSession, node distance=5cm] (pVisit) {Persist Page Visit};
\node [block,below of=pVisit] (end) {End};
% Draw edges
\path [line] (init) -- (hasSession);
\path [line] (hasSession) -- node [near start] {no} (pSession);
\path [line] (hasSession) -- node [near start] {yes} (pVisit);
\path [line] (pVisit) -- (end);
\end{tikzpicture}
\end{document}