2

Instead of drawing each arrow separately, I am interested in a quicker way to draw arrows along a path in a flowchart.

Let's look at some code first, MWE:

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{pgf,tikz}
\usetikzlibrary{chains,positioning,arrows,shapes.geometric,quotes,fit,calc}

\tikzstyle{startstop} = [%
rectangle,
rounded corners,
%   minimum width=3cm,
%   max width=2cm,
minimum height=1cm,
text centered,
text width=2cm,
line width=1pt,
draw=DarkBlue,
fill=DarkBlue!30
]

\tikzstyle{process} = [%
rectangle,
%   minimum width=3cm,
%   max width=2cm,
minimum height=1cm,
text centered,
text width=2cm,
draw=orange,
fill=orange!30
]

\tikzstyle{arrow} = [%
thick,
->,
>=stealth,
]

\tikzstyle{mainarrow} = [%
ultra thick,
->,
>=stealth,
]

\begin{document}

    \begin{tikzpicture}
    \node (mycenternode) [startstop]                      {Isgrind};
    \node (mynorthnode)  [process, above=of mycenternode] {Sami};
    \node (mysouthnode)  [process, below=of mycenternode] {Romrike};
    \node (mywestnode)   [process, left=of mycenternode]  {Rykinmaa};
    \node (myeastnode)   [process, right=of mycenternode] {Lukinsola};

    \draw [mainarrow] (mynorthnode)  --                           (mycenternode);
    \draw [mainarrow] (mycenternode) -- node[anchor=west]  {kuf}  (mysouthnode);
    \draw [arrow] (mywestnode)   -- node[anchor=south] {ders} (mycenternode);
    \draw [arrow] (mycenternode)  -- node[anchor=south]  {olan} (myeastnode);

    \path [arrow] (mywestnode) |- node[anchor=south] {punrot} (mynorthnode) -| (myeastnode);
    \end{tikzpicture}

\end{document}

Instead of having to say

    \draw [mainarrow] (mynorthnode)  -- (mycenternode);
    \draw [mainarrow] (mycenternode) -- node[anchor=west]  {kuf}  (mysouthnode);
    \draw [arrow] (mywestnode) -- node[anchor=south] {ders} (mycenternode);
    \draw [arrow] (mycenternode) -- node[anchor=south]  {olan} (myeastnode);

I wonder how to shorten that to something like

\path [mainarrow] (mynorthnode)  -- (mycenternode) -- node[anchor=west]  {kuf}  (mysouthnode);
\path [arrow] (mywestnode) -- node[anchor=south] {ders} (mycenternode) -- node[anchor=south]  {olan} (myeastnode);

EXTRA: In the last few lines, you can discern a \path. I don't really understand why it's not drawing anything.

  • \path and \draw are two different things. \path does not draw unless you say \path[draw,...]. Also consider using \tikzset{blabla/.style={...} instead of \tikzstyle{blabla}=[...]. – marmot Jan 22 at 18:07
3

I think you are looking for the edge operation. You were already loading quotes (and several packages that you do not use), which allows you to attach the labels to the arrows with a shorter syntax. The relevant piece of your code can thus be condensed to

\draw  (mynorthnode)  edge[mainarrow]  (mycenternode) 
    (mycenternode) edge[mainarrow,"kuf"]    (mysouthnode)
     (mywestnode)   edge[arrow,"ders"] (mycenternode)
  (mycenternode)  edge[arrow,"olan"] (myeastnode);

Note that \path alone does not draw. This is the reason why the lines do not appear. I added two styles for edges with corners, BR and BL, such that the path in the end can be drawn with edges as well,

\draw [arrow] (mywestnode)  edge[BR,"punrot"] (mynorthnode)
 (mynorthnode) edge[BL] (myeastnode);

This is the MWE with some unused libraries removed and \tikzset instead of \tikzstyle.

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{pgf,tikz}
\usetikzlibrary{positioning,quotes}

\tikzset{startstop/.style={
rectangle,
rounded corners,
%   minimum width=3cm,
%   max width=2cm,
minimum height=1cm,
text centered,
text width=2cm,
line width=1pt,
draw=DarkBlue,
fill=DarkBlue!30},
process/.style={%
rectangle,
%   minimum width=3cm,
%   max width=2cm,
minimum height=1cm,
text centered,
text width=2cm,
draw=orange,
fill=orange!30},
arrow/.style={%
thick,
->,
>=stealth,
},
mainarrow/.style={%
ultra thick,
->,
>=stealth,
},
BR/.style={ to path={|- (\tikztotarget)  \tikztonodes}},
BL/.style={ to path={-| (\tikztotarget)  \tikztonodes}}}

\begin{document}

\begin{tikzpicture}
    \node (mycenternode) [startstop]                      {Isgrind};
    \node (mynorthnode)  [process, above=of mycenternode] {Sami};
    \node (mysouthnode)  [process, below=of mycenternode] {Romrike};
    \node (mywestnode)   [process, left=of mycenternode]  {Rykinmaa};
    \node (myeastnode)   [process, right=of mycenternode] {Lukinsola};

    \draw  (mynorthnode)  edge[mainarrow]  (mycenternode) 
        (mycenternode) edge[mainarrow,"kuf"]    (mysouthnode)
         (mywestnode)   edge[arrow,"ders"] (mycenternode)
      (mycenternode)  edge[arrow,"olan"] (myeastnode);

    \draw [arrow] (mywestnode)  edge[BR,"punrot"] (mynorthnode)
     (mynorthnode) edge[BL] (myeastnode);
\end{tikzpicture}
\end{document}

enter image description here

2

You will only get one arrow tip when you use --, but if you use edge instead, you'll get an arrow tip for each segment, as edge inserts a separate path (I think). Anyways, you can actually make do with specifying the center node only once:

\path [mainarrow]  (mycenternode) edge[<-]                          (mynorthnode)
                                  edge           node[right] {kuf}  (mysouthnode)
                                  edge[arrow,<-] node[above] {ders} (mywestnode)
                                  edge[arrow]    node[above] {olan} (myeastnode);
  • By using the quotes syntax marmot demonstrates in his answer, you can shorten this a bit more. – Torbjørn T. Jan 22 at 18:20
  • I must deduce, that, as soon as the diagram is not a cross any more, but a longer chain, I won't get around repeating the nodes in the chain. This being the case, I take from both of your answers that a chain without repetition of the nodes involved is not possible. Then marmot's answer becomes more in-depth. – thymaro Jan 22 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.