我怎样才能建立如附图所示的连接?我试过在代码中添加一行注释,但没有起作用。
\documentclass{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.arrows}
\usepackage{array}
\begin{document}
\begin{tikzpicture} [
auto,
decision/.style = { diamond, draw=black, thick, fill=gray!30, text width=5em, text centered, inner sep=1pt },
block/.style = { rectangle, draw=black, thick, fill=white, text width=10em, text centered, minimum height=2em },
line/.style = { draw, thick, ->, shorten >=1pt },
]
% Define nodes in a matrix
\matrix [column sep=5mm, row sep=6mm] {
& \node [block] (H) {Calculate H}; & \\
& \node [block] (eq3) {Solve Eq.3}; & \\
& \node [decision] (y) {$y\left(\frac{L}{2}\right)=h$}; & \\
& \node [block] (Dy) {Update $y(x)$}; & \\
& \node [block] (Hnew) {Calculate H}; & \\
& \node [decision] (HH) {H changed?}; & \\
& \node [text centered] (out) {Results}; & \\
};
% connect all nodes defined above
\begin{scope} [every path/.style=line]
\path (H) -- (eq3);
\path (eq3) -- (y);
\path (HH) --++ (-3,0) node [near start] {yes} |- (eq3);
\path (y) -- node [near start] {no} (Dy);
% \path (y) -- (3,0) node [near start] {yes} -| (Hnew); THIS WAS MY TRY!!! NOT WORKING
\path (Dy) -- (Hnew);
\path (Hnew) -- (HH);
\path (HH) -- node [near start] {no} (out);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
如果你换线
% \path (y) -- (3,0) node [near start] {yes} -| (Hnew); THIS NOT WORKING
在你的姆韦到
\path (y.east) node [above right] {yes} -- + (2,0) |- (Hnew);
你将获得:
然而,由于流程图相对简单,可以使用chains
代替 来简化其代码matrix
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains, positioning, shapes}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
\begin{document}
\begin{tikzpicture} [
node distance = 5mm and 1mm,
start chain = A going below,
decision/.style = { diamond, aspect=1.5, draw=black, thick, fill=gray!30,
text width=5em, align=center, inner sep=1pt,
on chain=A, join=by line},
block/.style = { rectangle, draw=black, thick, fill=white,
text width=10em, align=center, minimum height=2em,
on chain=A, join=by line},
line/.style = { draw, thick, ->, shorten >=1pt },
]
% Define nodes in a matrix
\node [block] {Calculate H}; % A-1
\node [block] {Solve Eq.3}; % A-2
\node [decision] {$y\left(\frac{L}{2}\right)=h$}; % A-3
\node [block] {Update $y(x)$}; % A-4
\node [block] {Calculate H}; % A-5
\node [decision] {H changed?}; % A-6
% non join nodes' connections
\draw[line] (A-6.west) node [above left] {yes} -- + (-2,0) |- (A-2);
\draw[line] (A-3.east) node [above right] {yes} -- + ( 2,0) |- (A-5);
% edge labels
\node[below right] at (A-3.south) {no};
\draw[line] (A-6.south) -- ++ (0,-0.6) node [below] {Results};
\end{tikzpicture}
\end{document}