# How can I move arrows towards left or right in a tikz figure?

I have been trying to draw a flowchart using tikz. I took help from the overleaf's guide to define the elements. Overleaf LaTeX Graphics using TikZ: A Tutorial for Beginners (Part 3)—Creating Flowcharts This works fine until I faced a complicated chart that goes back several steps from decision block. The code I used:

    \documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{xcolor}
\usepackage[colorlinks=true,urlcolor=blue,citecolor=blue]{hyperref}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{io} = [trapezium, trapezium left angle=80, trapezium right angle=100, minimum width=1cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}
\section{Example of a Flowchart}
%
\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance=2cm]
\node (W) [io]{Some Matrix A};
\node (C) [io, right of=W, xshift=6cm]{Some Matrix B};
\node (Comp3) [process, below of=W]{Compute this};
\node (Comp4) [process, below of=C]{Compute that};
\node (Proc) [process, below of=Comp3, xshift=4cm]{Compare result A with result B sequentially};
\node (Match) [decision, below of=Proc, yshift=-0.5cm] {Match found ?};
\node (Comp5) [process, below of=Match,yshift=-0.5cm]{Found this match};

\draw [arrow] (W) -- (Comp3);
\draw [arrow] (C) -- (Comp4);
\draw [arrow] (Comp3) |- (Proc);
\draw [arrow] (Comp4) |- (Proc);
\draw [arrow] (Proc) -- (Match);
\draw [arrow] (Match) -- node[anchor=east] {Yes} (Comp5);
\draw [arrow] (Match) -| node[anchor=north] {No} (Comp4);
\end{tikzpicture}
\end{figure}

\end{document}


In the result, the two arrows got merged. I want to create some horizontal space between them. Is there any way to introduce space or adjust the starting and ending point for those arrows? Or to make curved arrows, instead of straight lines?

• Hi and welcome. Please give a fully compilable code. – AndréC Jul 29 '20 at 19:43
• Take a look at xshift? – projetmbc Jul 29 '20 at 19:48
• @AndréC I edited the body. – Wave_Rider03 Jul 29 '20 at 20:02
• @projetmbc Where to add the shift command? I was trying to do '- [xshift=2cm] |' but got error. – Wave_Rider03 Jul 29 '20 at 20:02

## 1 Answer

The code you found somewhere is very old code that was written with the syntax of TikZ version 2. With TikZ 3.0, the code has evolved and makes it much easier to manage the relative positioning of nodes. To do so, just load the positioning library.

For example, when the old syntax is below of=W the new one is below=of W. You will notice that = and of are written in reverse.

With this new syntax, I place the nodes in a different order than in your code. I updated the syntax of the styles which are also written with the old syntax.

Translated with www.DeepL.com/Translator (free version)

\documentclass[tikz,border=5mm]{standalone}

\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{positioning}
\tikzset{io/.style = {trapezium, trapezium left angle=80, trapezium right angle=100, minimum width=1cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
process/.style = {rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
every arrow/.style={thick,>=stealth}}
\begin{document}

\begin{tikzpicture}%[node distance=1cm]
\node (W) [io]{Some Matrix A};
\node (Comp3) [process, below =of W]{Compute this};
\node (Proc) [process, below right=of Comp3]{Compare result A with result B sequentially};
\node (Comp4) [process, above right =of Proc]{Compute that};
\node (C) [io, above =of Comp4]{Some Matrix B};
\node (Match) [decision, below =of Proc] {Match found ?};
\node (Comp5) [process, below =of Match]{Found this match};

\draw [->] (W) -- (Comp3);
\draw [->] (C) -- (Comp4);
\draw [->] (Comp3) |- (Proc);
\draw [->] (Comp4.230) |- (Proc);
\draw [->] (Proc) -- (Match);
\draw [->] (Match) -- node[anchor=east] {Yes} (Comp5);
\draw [->] (Match) -| node[anchor=north] {No} (Comp4.310);
\end{tikzpicture}

\end{document}

• Thanks a lot. This works perfectly. Yes, the Overleaf tutorial page did mention that they were using old syntax. Would you please suggest to me some sources where I can read more about the modern tikz syntax and features? – Wave_Rider03 Jul 29 '20 at 20:27
• Personally I always use the manual that is installed and updated with the MikTeX distribution. There is a very interesting version called VisualTikZ which has no text but only examples of the effects of the syntax – AndréC Jul 29 '20 at 20:32