4

how can i connect two blocks with a circular arrow? Please see below the example that i've managed to create so far:

\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}

This is the current result: enter image description here

This is a quick sketch of the result i would like to have: enter image description here

3 Answers3

3

You can use for example the "bend"-option with \path [line] (4) to[bend left=65] (1);

In your code it will be

\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);

By changing the value you can change the angles of the line.

Latain
  • 51
2

You could play with to[out=..., in=...], where out and in are respectively the angle of exit and entry to the node. You could also choose the anchor position, for example (2.60) means node named 2 at 60 degrees, 0 is east.

By the way:

  1. Should \tikzset or \tikzstyle be used to define TikZ styles?
  2. Difference between "right of=" and "right=of" in PGF/TikZ
  3. moreover, tikzset sets the style for all your tikzpictures, if you want to set them only for the current picture, just put them directly as tikzpicture environment options.

Here my 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

CarLaTeX
  • 62,716
1

A little bit automated but sure not perfect:

\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}

Output:

enter image description here

koleygr
  • 20,105