流程图 Tikzpicture - 从路径绘制箭头

流程图 Tikzpicture - 从路径绘制箭头

我正在使用 tikzpicture 包创建流程图。

因为空间不够,所以我想从一条路径画一个箭头到一个盒子。

使用下面这段代码,我想要一个从 Kmeans 和 KGaussians 之间的路径开始并循环回到 Kmeans 的箭头。

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=gray!20, 
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=gray!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) {User input};
\node [block, below of=init] (denoise) {denoise};
\node [block, below of=denoise] (Kmeans) {K means};
\node [block, below of=Kmeans] (KGaussians) {K Gaussians};
\node [block, below of=KGaussians] (output) {Output};     
% Draw edges
\path [line] (init) -- (denoise);
\path [line] (denoise) -- (Kmeans);
\path [line] (Kmeans) -- (KGaussians);
\path [line] (KGaussians) -- (output);
\end{tikzpicture}

\end{document}

我正在考虑添加如下命令行:

\draw [arrow] (\path (Kmeans) -- (KGaussians)) |- (Kmeans);

谢谢!

答案1

如果没有该库(建议在评论中),您可以在和calc之间的路径中间放置一个辅助坐标:KmeansKGaussians

\path [line] (Kmeans) -- coordinate (aux) (KGaussians);

然后使用该坐标绘制所需的路径,如下所示

\path [line] (aux) -- ++(-1.5,0) |- (Kmeans.west);

完整示例:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=gray!20, 
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=gray!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) {User input};
\node [block, below of=init] (denoise) {denoise};
\node [block, below of=denoise] (Kmeans) {K means};
\node [block, below of=Kmeans] (KGaussians) {K Gaussians};
\node [block, below of=KGaussians] (output) {Output};     
% Draw edges
\path [line] (init) -- (denoise);
\path [line] (denoise) -- (Kmeans);
\path [line] (Kmeans) -- coordinate (aux) (KGaussians);
\path [line] (KGaussians) -- (output);
\path [line] (aux) -- ++(-1.5,0) |- (Kmeans.west);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容