1

I'm trying to create the schema in tikz latex. I need to have arrows between nodes and arrows to the same node. The arrow to the same node has to be outside the node. It has to start on the top right of the box and end on the top left of the box.

How to add a bent arrow to the box as shown in the picture. I would love to have the same arrow as shown in the screenshot.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
node distance=1.5cm and 1cm,
ar/.style={->,>=latex},
middle_node/.style={
  draw,
  text width=1.5cm,
  minimum height=0.75cm,
  align=center
  },
end_node/.style={
  draw,
  text width=1cm,
  minimum height=0.55cm,
  align=center
  }
]

  % nodes
  \node[end_node] (start) {\textbf{start}};
  \node[middle_node,right=of start] (first_step) {a};
  \node[middle_node,right=of first_step] (second_step) {b};
  \node[middle_node,right=of second_step] (third_step) {c}; 
  \node[end_node, right=of third_step] (stop) {\textbf{stop}};

  % lines
  \draw[ar] (start) -- (first_step);
  % here i don know how to bend this arrow to the same box
  \draw[ar] (first_step.80) -- (first_step.180);
  \draw[ar] (first_step) -- (second_step);
  \draw[ar] (second_step) -- (third_step);
  \draw[ar] (third_step) -- (stop);
\end{tikzpicture}
\end{document}
3
  • 1
    Did you try \draw[ar] (first_step) edge[loop above] ();? Commented Oct 23, 2022 at 7:58
  • Is it for automata, or for functional block diagrams?
    – projetmbc
    Commented Oct 23, 2022 at 8:48
  • for automata :) Commented Oct 23, 2022 at 9:01

1 Answer 1

2

You can use a to-path with the option loop above or, more explicitly, with the options out=75, in=105, loop or similar:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
node distance=1.5cm and 1cm,
ar/.style={->,>=latex},
middle_node/.style={
  draw,
  text width=1.5cm,
  minimum height=0.75cm,
  align=center
  },
end_node/.style={
  draw,
  text width=1cm,
  minimum height=0.55cm,
  align=center
  }
]

  % nodes
  \node[end_node] (start) {\textbf{start}};
  \node[middle_node,right=of start] (first_step) {a};
  \node[middle_node,right=of first_step] (second_step) {b};
  \node[middle_node,right=of second_step] (third_step) {c}; 
  \node[end_node, right=of third_step] (stop) {\textbf{stop}};

  % lines
  \draw[ar] (start) -- (first_step);
  % here i don know how to bend this arrow to the same box
  \draw[ar] (first_step) to[loop above] ();
  \draw[ar] (first_step) -- (second_step);
  \draw[ar] (second_step) to[out=75, in=105, loop] ();
  \draw[ar] (second_step) -- (third_step);
  \draw[ar] (third_step) -- (stop);
\end{tikzpicture}
\end{document}

enter image description here


If you want to start and end the loop exactly on the edges of the node, you should use the north east and north west anchors and perhaps use the looseness option to adjust how the loop is bent:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[
node distance=1.5cm and 1cm,
ar/.style={->,>=latex},
middle_node/.style={
  draw,
  text width=1.5cm,
  minimum height=0.75cm,
  align=center
  },
end_node/.style={
  draw,
  text width=1cm,
  minimum height=0.55cm,
  align=center
  }
]

  % nodes
  \node[end_node] (start) {\textbf{start}};
  \node[middle_node,right=of start] (first_step) {a};
  \node[middle_node,right=of first_step] (second_step) {b};
  \node[middle_node,right=of second_step] (third_step) {c}; 
  \node[end_node, right=of third_step] (stop) {\textbf{stop}};

  % lines
  \draw[ar] (start) -- (first_step);
  % here i don know how to bend this arrow to the same box
  \draw[ar] (first_step.north east) to[in=110, out=70, looseness=2] (first_step.north west);
  \draw[ar] (first_step) -- (second_step);
  \draw[ar] (second_step) -- (third_step);
  \draw[ar] (third_step) -- (stop);
\end{tikzpicture}
\end{document}

enter image description here

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .