连接底部蓝色矩形“从 H 更新 E”和红色菱形“完成”的箭头有两个不连续之处。我该如何修复下面的代码以在空节点处连接这些线?
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows}
\begin{document}
\begin{figure}
\begin{center}
\tikzstyle{greenrect} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text justified, draw=black, fill=green!60]
\tikzstyle{bluerect} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text justified, draw=black, fill=blue!50]
\tikzstyle{whiterect} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black]
\tikzstyle{reddiamond} = [diamond, minimum width=1cm, minimum height=1cm, text centered, draw=black, fill=red!80]
\tikzstyle{arrow} = [thick,->,>=stealth, line width=1.5pt]
\tikzstyle{line} = [thick,-,>=stealth, line width=1.5pt]
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node(Initialize) [greenrect] {
\begin{tabular}{c}Initialize Fields to Zero\\$\vec{E} = \vec{H} = 0$ \end{tabular}
};
\node (Done) [reddiamond, below of=Initialize] {Done};
\node(E2H) [bluerect, below of=Done, node distance=3cm] {
\begin{tabular}{c}Update H from E\\
$\displaystyle{\vec{H}\Bigr\lvert_{t+\triangle t/2} = \vec{H}\Bigr\lvert_{t-\triangle t/2} - \frac{\triangle t}{\mu} (\nabla \times \vec{E}\Bigr\lvert_{t})}$\\
\end{tabular}
};
\node (H2E) [bluerect, below of=E2H, node distance=2.5cm] {
\begin{tabular}{c} Update E from H \\
$\displaystyle{\vec{E}\Bigr\lvert_{t+\triangle t/2} = \vec{E}\Bigr\lvert_{t-\triangle t/2} - \frac{\triangle t}{\epsilon} (\nabla \times \vec{H}\Bigr\lvert_{t})}$\\
\end{tabular}
};
\node (Finished) [right of=Done, node distance=6cm] {
\begin{tabular}{c}
Finished\\
\end{tabular}
};
\node (Empty1) [below of=H2E, node distance=2cm] {};
\node (Empty2) [left of=Empty1, node distance=5cm] {};
\node (Empty3) [left of=Done, node distance=5cm] {};
\draw [arrow] (Initialize) -- (Done);
\draw [arrow] (Done) -- node[name=no] {No} (E2H);
\draw [arrow] (E2H) -- (H2E);
\draw [arrow] (Done) -- node[name=yes] {Yes} (Finished);
\draw [line] (H2E) -- (Empty1);
\draw [line] (Empty1) -| (Empty2);
\draw [line] (Empty2) |- (Empty3);
\draw [arrow] (Empty3) -- (Done);
\end{tikzpicture}
\end{center}
\caption{Block diagram describing a simple FDTD Algorithm}
\end{figure}
\end{document}
答案1
使用\coordinate
s 代替\node
s:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows,positioning}
\begin{document}
\begin{figure}
\begin{center}
\tikzstyle{greenrect} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text justified, draw=black, fill=green!60]
\tikzstyle{bluerect} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text justified, draw=black, fill=blue!50]
\tikzstyle{whiterect} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black]
\tikzstyle{reddiamond} = [diamond, minimum width=1cm, minimum height=1cm, text centered, draw=black, fill=red!80]
\tikzstyle{arrow} = [thick,->,>=stealth, line width=1.5pt]
\tikzstyle{line} = [thick,-,>=stealth, line width=1.5pt]
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
\node(Initialize) [greenrect] {
\begin{tabular}{c}Initialize Fields to Zero\\$\vec{E} = \vec{H} = 0$ \end{tabular}
};
\node (Done) [reddiamond, below of=Initialize] {Done};
\node(E2H) [bluerect, below of=Done, node distance=3cm] {
\begin{tabular}{c}Update H from E\\
$\displaystyle{\vec{H}\Bigr\lvert_{t+\triangle t/2} = \vec{H}\Bigr\lvert_{t-\triangle t/2} - \frac{\triangle t}{\mu} (\nabla \times \vec{E}\Bigr\lvert_{t})}$\\
\end{tabular}
};
\node (H2E) [bluerect, below of=E2H, node distance=2.5cm] {
\begin{tabular}{c} Update E from H \\
$\displaystyle{\vec{E}\Bigr\lvert_{t+\triangle t/2} = \vec{E}\Bigr\lvert_{t-\triangle t/2} - \frac{\triangle t}{\epsilon} (\nabla \times \vec{H}\Bigr\lvert_{t})}$\\
\end{tabular}
};
\node (Finished) [right of=Done, node distance=6cm] {
\begin{tabular}{c}
Finished\\
\end{tabular}
};
\coordinate[below = 2cm of H2E] (Empty1);
\coordinate[left=5cm of Empty1] (Empty2);
\coordinate[left = 5cm of Done] (Empty3);
\draw [arrow] (Initialize) -- (Done);
\draw [arrow] (Done) -- node[name=no] {No} (E2H);
\draw [arrow] (E2H) -- (H2E);
\draw [arrow] (Done) -- node[name=yes] {Yes} (Finished);
\draw [arrow]
(H2E) -- (Empty1) -- (Empty2) |- (Done);
\end{tikzpicture}
\end{center}
\caption{Block diagram describing a simple FDTD Algorithm}
\end{figure}
\end{document}
结果:
评论:
不要使用旧的弃用
of=
语法,而是使用定位库和=of
(参见我用于放置坐标的代码中的示例)。而不是旧的
\tikzstyle
用法\tikzset
(参考包文档)。您可以使用简单的方法轻松绘制箭头
\draw [arrow] (H2E) -- (Empty1) -- (Empty2) |- (Done);