流程图中块之间的循环连接

流程图中块之间的循环连接

我怎样才能用圆形箭头连接两个块?请参见下面我迄今为止成功创建的示例:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[node distance = 3cm, auto]

\tikzstyle{block} = [rectangle, draw, fill=white!20, 
text width=5.5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']


\node [block] (1) {Text 1};
\node [block, below right of=1] (2) {Text 2};
\node [block, below left of=2] (3) {Text 3};
\node [block, above left of=3] (4) {Text 4};

\path [line] (1) -- (2);
\path [line] (2) -- (3);
\path [line] (3) -- (4);
\path [line] (4) -- (1);
\end{tikzpicture}
\end{document}

这是目前的结果: enter image description here

这是我想要的结果的简要概述: enter image description here

答案1

你可以使用to[out=..., in=...],其中outin分别是节点的出口和入口角度。你也可以选择锚点位置,例如表示以度(2.60)命名的节点位于东边。2600

顺便一提:

  1. 应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?
  2. PGF/TikZ 中“right of=”和“right=of”之间的区别
  3. 此外,tikzset设置所有图片的样式tikzpicture,如果您只想为当前图片设置样式,只需将它们直接作为tikzpicture环境选项即可。

这是我的 MWE:

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

\begin{document}
    \pagestyle{empty}

    \begin{tikzpicture}[
        node distance=4ex and 0em,
        block/.style={rectangle, draw, fill=white!20, 
    text width=5.5em, text centered, rounded corners, minimum height=4em},
        line/.style={draw, -latex},
        ]

        \node [block] (1) {Text 1};
        \node [block, below right= of 1] (2) {Text 2};
        \node [block, below left= of 2] (3) {Text 3};
        \node [block, above left= of 3] (4) {Text 4};

        \path [line] (1.east) to[out=0, in=90] (2.60);
        \path [line] (2.-60) to[out=-90, in=0] (3.east);
        \path [line] (3.west) to[out=180, in=-90] (4.-120);
        \path [line] (4.120) to[out=90, in=180] (1.west);
    \end{tikzpicture}
\end{document}

enter image description here

答案2

例如,您可以将“bend”选项与 \path [line] (4) to[bend left=65] (1) 一起使用;

在您的代码中它将

\path [line] (1) to[bend left=45] (2);
\path [line] (2) to[bend left=45] (3);
\path [line] (3) to[bend left=45] (4);
\path [line] (4) to[bend left=45] (1);

通过改变该值,您可以改变线的角度。

答案3

有点自动化但肯定不完美:

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

\newcommand{\circular}[2]{
\node (0) at (0,0){};
\xdef\Radious{#2}
\foreach \nodetext[count=\i] in {#1} {
\xdef\totalIt{\i}
}
\foreach \nodetext[count=\i] in {#1} {
\pgfmathsetmacro\myprev{int{\i-1}}
\pgfmathsetmacro\curxdispl{cos(90-360/\totalIt*(\i-1))*\Radious}
\pgfmathsetmacro\curydispl{sin(90-360/\totalIt*(\i-1))*\Radious}
\path  ($(\curxdispl cm,\curydispl cm)$) node[block,anchor=center] (\i) {\nodetext};
}

\foreach \nodetext[count=\i] in {#1}{
\pgfmathsetmacro\mynext{\ifnum\i<\totalIt int(\i+1)\else 1\fi}
\path[draw,-latex] (\i) to[bend left] (\mynext);
}
}

\begin{document}
\pagestyle{empty}




\begin{tikzpicture}
\tikzstyle{block} = [rectangle, draw, fill=white!20, 
text width=2.5em, text centered, rounded corners, minimum height=3em]
\circular{test1,test2,test3}{2}
\end{tikzpicture}\vspace{40pt}

\begin{tikzpicture}
\tikzstyle{block} = [rectangle, draw, fill=white!20, 
text width=3.5em, text centered, rounded corners, minimum height=2em]
\circular{test1,test2,test3,test4,test5}{4}
\end{tikzpicture}
\end{document}

输出:

enter image description here

相关内容