14

I have a diagram with 5 nodes and edges to each other, which leads to clumpy corners:

\documentclass[parskip=half]{scrreprt}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\tikzset{subjekt/.style={rectangle,draw,minimum height=.7cm, minimum width=2.5cm, align=center},
         strom/.style={line width=3pt, shorten >=2pt,shorten <=2pt},
         gueterstrom/.style={strom,Goldenrod,->},
         geldstrom/.style={strom,SlateGrey,->}}
\begin{document}
  \begin{tikzpicture}[node distance=5cm]
    \node[subjekt] (H) at (0,0) {Haushalt};
    \node[subjekt] (U) [below right= of H] {Unternehmen};
    \node[subjekt] (S) [above right= of U] {Staat};
    \node[subjekt] (B) [below left= of U]  {Banken};
    \node[subjekt] (A) [below right= of U] {Ausland};
    \draw (H) edge[bend right=10,geldstrom] node[left] {3} (B);
    \draw (B) edge[bend right=10,geldstrom] node[right] {9} (H);
    \draw (H) edge[bend right=10,geldstrom] node[below] {1} (S);
    \draw (S) edge[bend right=10,geldstrom] node[above] {13} (H);
    \draw (H) edge[bend right=10,geldstrom] node[below left] {2} (U);
    \draw (U) edge[bend right=10,geldstrom] node[above right] {6} (H);
    \draw (H) edge[bend right=22,geldstrom, near end] node[below left] {4} (A);
    \draw (A) edge[bend right=22,geldstrom, near end] node[above right] {20} (H);
    \draw (B) edge[bend right=10,geldstrom] node[below right] {10} (U);
    \draw (U) edge[bend right=10,geldstrom] node[above left] {7} (B);
    \draw (B) edge[bend right=10,geldstrom] node[below] {12} (A);
    \draw (A) edge[bend right=10,geldstrom] node[above] {19} (B);
    \draw (B) edge[bend right=22,geldstrom, near end] node[below right] {11} (S);
    \draw (S) edge[bend right=22,geldstrom, near end] node[above left] {16} (B);
    \draw (A) edge[bend right=10,geldstrom] node[above right] {18} (U);
    \draw (U) edge[bend right=10,geldstrom] node[below left] {8} (A);
    \draw (A) edge[bend right=10,geldstrom] node[right] {17} (S);
    \draw (S) edge[bend right=10,geldstrom] node[left] {14} (A);
    \draw (S) edge[bend right=10,geldstrom] node[above left] {15} (U);
    \draw (U) edge[bend right=10,geldstrom] node[below right] {5} (S);
  \end{tikzpicture}
\end{document}

mwe

Any idea how to improve the situation in the corners?

  • 1
    Just a thought: instead of two arrows going back and forth just one with two heads. – marmot Mar 26 '18 at 16:30
  • Change rectangle to circle? – erik Mar 26 '18 at 16:33
  • @marmot That's not possible, there are two different money streams -> numbers for explanation – Josef Mar 26 '18 at 16:35
  • You could still place the streams (numbers) above and below (or left and right) of the arrow and indicate the directions by small arrows. – marmot Mar 26 '18 at 16:37
23

like this?

enter image description here

edit

in comparison to your code the code in mwe, by which the above image was drawm, has the following changes/improvements:

  • by introducing library quotes writing of edge labels is simplified and much shorter. for example, instead of

\draw (H) edge[bend right=10,geldstrom] node[left] {3} (B);

is possible obtain the same result with

\draw (H) edge ["3"] (B)

where for edge i define style, which determine edge color, thickness, shortness and bending angle:

every edge/.style = {draw=SlateGrey, -Stealth, line width=2pt,
                     shorten <=5pt, shorten > = 5pt,
                     bend right=8},
  • the angle of bending is essentially determined by trial and error method. however there i exploit my experiences from drawing of the similar diagrams and knowledge of geometry (already my first trial was successful). in the edge style i determine the most common angle, exceptions for four edges are determined locally.
  • since edges style is defined, there is no more need to write \draw ... : for each edge. it is sufficient write it ones and then list all edges (see mwe below).
  • with style edge quotes is determined font size and position of edge labels.
  • size of nodes shapes is also changed. used bigger height (and also with shortening of edges) prevent edges overlaps.
  • with library arrows.meta is defined on decent ways arrows heads
  • summary of tikzpicture changes are:

    • style subjekt is renewed
    • styles strom, gueterstrom and geldstrom are replaced by every edge and every edge quotes

\documentclass[parskip=half]{scrreprt}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes,
                shapes}

\begin{document}
  \begin{tikzpicture}[auto=right,
    node distance = 44mm,
   subjekt/.style = {draw, semithick, minimum height=12mm, minimum width=24mm},
every edge/.style = {draw=SlateGrey, -Stealth, line width=2pt,
                     shorten <=5pt, shorten > = 5pt,
                     bend right=8},
every edge quotes/.append style = {inner sep=2pt, font=\small, pos=0.6},
                    ]
\node (H) [subjekt]                     {Haushalt};
\node (U) [subjekt,below right=of H]    {Unternehmen};
\node (S) [subjekt,above right=of U]    {Staat};
\node (B) [subjekt,below left =of U]    {Banken};
\node (A) [subjekt,below right=of U]    {Ausland};
%
\draw   (H) edge ["3"]  (B)
        (B) edge ["9"]  (H)
        (H) edge ["1"]  (S)
        (S) edge ["13"] (H)
        (H) edge ["2"]  (U)
        (U) edge ["6"]  (H)
%
        (H) edge [bend right=24, "4"]  (A)
        (A) edge [bend right=24, "20"] (H)
%
        (B) edge ["10"] (U)
        (U) edge ["7"]  (B)
        (B) edge ["12"] (A)
        (A) edge ["19"] (B)
%
        (B) edge [bend right=24, "11"] (S)
        (S) edge [bend right=24, "16"] (B)
%
        (A) edge ["18"] (U)
        (U) edge ["8"]  (A)
        (A) edge ["17"] (S)
        (S) edge ["14"] (A)
        (S) edge ["15"] (U)
        (U) edge ["5"]  (S);
  \end{tikzpicture}
\end{document}
  • 1
    The best answer! But adding some details instead of „like this“ would probably help. For the bend right values: trial and error to choose them? – Patwie Mar 27 '18 at 5:20
  • @Patwie, i will ad some explanation [regardless that the code is self explanatory to me :-) ] asap. for bending angle i essential use trial and error method, however my experiences from drawings and use of geometry help me that was my first trial successful :-) – Zarko Mar 27 '18 at 11:50
  • @Patwie, see added explanations in edit of answer. is now better? – Zarko Mar 27 '18 at 12:37
  • @Zarko: I don't see any edits... – Rahul Mar 27 '18 at 12:42
  • oh, i forgot upload them :-(. now are presented :-) – Zarko Mar 27 '18 at 12:43
17

The arrangement you chose is very suboptimal for a fully connected graph. It is better to arrange things in a circular layout.

TikZ graphdrawing requires LuaTeX.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,quotes}
\usegdlibrary{circular}
\begin{document}

\begin{tikzpicture}
  \graph[
  simple necklace layout,
  edges={bend right=10},
  edge quotes={fill=white,inner sep=1pt,font=\tiny},
  nodes={draw},
  node sep=5em,
  ] {
    Haushalt -> {Staat [>"1"], Unternehmen [>"2"], Banken [>"3"], Ausland [>"4"]},
    Unternehmen -> {Haushalt [>"6"], Staat [>"5"], Banken [>"7"], Ausland [>"8"]},
    Banken -> {Haushalt [>"9"], Staat [>"11"], Unternehmen [>"10"], Ausland [>"12"]},
    Staat -> {Haushalt [>"13"], Unternehmen [>"15"], Banken [>"16"], Ausland [>"14"]},
    Ausland -> {Haushalt [>"20"], Staat [>"17"], Unternehmen [>"18"], Banken [>"19"]}
  };
\end{tikzpicture}

\end{document}

enter image description here

15

How to improve the situation in the corners? Get rid of the corners! I also changed the arrow tips and tightened things up a bit.

\documentclass[parskip=half]{scrreprt}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\tikzset{subjekt/.style={circle,draw,minimum height=.7cm, minimum width=2.2cm, align=center},
         strom/.style={line width=2pt, shorten >=2pt,shorten <=2pt},
         gueterstrom/.style={strom,Goldenrod,->},
         geldstrom/.style={strom,SlateGrey,->}}
\begin{document}
  \begin{tikzpicture}[node distance=4cm,>=stealth]
    \node[subjekt] (H) at (0,0) {Haushalt};
    \node[subjekt] (U) [below right= of H] {Unternehmen};
    \node[subjekt] (S) [above right= of U] {Staat};
    \node[subjekt] (B) [below left= of U]  {Banken};
    \node[subjekt] (A) [below right= of U] {Ausland};
    \draw (H) edge[bend right=10,geldstrom] node[left] {3} (B);
    \draw (B) edge[bend right=10,geldstrom] node[right] {9} (H);
    \draw (H) edge[bend right=10,geldstrom] node[below] {1} (S);
    \draw (S) edge[bend right=10,geldstrom] node[above] {13} (H);
    \draw (H) edge[bend right=10,geldstrom] node[below left] {2} (U);
    \draw (U) edge[bend right=10,geldstrom] node[above right] {6} (H);
    \draw (H) edge[bend right=22,geldstrom, near end] node[below left] {4} (A);
    \draw (A) edge[bend right=22,geldstrom, near end] node[above right] {20} (H);
    \draw (B) edge[bend right=10,geldstrom] node[below right] {10} (U);
    \draw (U) edge[bend right=10,geldstrom] node[above left] {7} (B);
    \draw (B) edge[bend right=10,geldstrom] node[below] {12} (A);
    \draw (A) edge[bend right=10,geldstrom] node[above] {19} (B);
    \draw (B) edge[bend right=22,geldstrom, near end] node[below right] {11} (S);
    \draw (S) edge[bend right=22,geldstrom, near end] node[above left] {16} (B);
    \draw (A) edge[bend right=10,geldstrom] node[above right] {18} (U);
    \draw (U) edge[bend right=10,geldstrom] node[below left] {8} (A);
    \draw (A) edge[bend right=10,geldstrom] node[right] {17} (S);
    \draw (S) edge[bend right=10,geldstrom] node[left] {14} (A);
    \draw (S) edge[bend right=10,geldstrom] node[above left] {15} (U);
    \draw (U) edge[bend right=10,geldstrom] node[below right] {5} (S);
  \end{tikzpicture}
\end{document}

enter image description here

  • That looks much better indeed. Unfortunately, the rectangles have an implicit meaning in a series of diagrams. – Josef Mar 26 '18 at 16:53
  • @Josef I see. I guess if such a trivial solution would work you wouldn't have posted the question. – erik Mar 26 '18 at 17:26
13

I really find the large number of lines a bit confusing, here is a proposal to reduce it.

\documentclass[parskip=half]{scrreprt}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}

\usetikzlibrary{arrows.meta,positioning,shapes,decorations.markings}
\tikzset{subjekt/.style={rectangle,draw,minimum height=.7cm, minimum width=2.5cm, align=center},
         strom/.style={line width=3pt, shorten >=2pt,shorten <=2pt},
         gueterstrom/.style={strom,Goldenrod,->},
         geldstrom/.style={strom,SlateGrey,-,
         postaction={decoration={markings,
            mark=at position 0.7 with {\arrow[shorten >=0pt,shorten <=0pt,->]
            {>}}},decorate}},
         bendstrom/.style={strom,SlateGrey,-,
         postaction={decoration={markings,
            mark=at position 0.8 with {\arrow[shorten >=0pt,shorten <=0pt,->]
            {>}}},decorate}}}
\begin{document}
  \begin{tikzpicture}[node distance=5cm,>=Stealth]
    \node[subjekt] (H) at (0,0) {Haushalt};
    \node[subjekt] (U) [below right= of H] {Unternehmen};
    \node[subjekt] (S) [above right= of U] {Staat};
    \node[subjekt] (B) [below left= of U]  {Banken};
    \node[subjekt] (A) [below right= of U] {Ausland};
    \begin{scope}[inner sep=6pt,pos=0.68]
    \draw (H) edge[geldstrom] node[left] {3} (B);
    \draw (B) edge[geldstrom] node[left] {9} (H);
    \draw (H) edge[geldstrom] node[above] {1} (S);
    \draw (S) edge[geldstrom] node[above] {13} (H);
    \draw (H) edge[geldstrom] node[above right] {2} (U);
    \draw (U) edge[geldstrom] node[above right] {6} (H);
    \draw (B) edge[geldstrom] node[below right] {10} (U);
    \draw (U) edge[geldstrom] node[below right] {7} (B);
    \draw (B) edge[geldstrom] node[below] {12} (A);
    \draw (A) edge[geldstrom] node[below] {19} (B);
    \draw (A) edge[geldstrom] node[above right] {18} (U);
    \draw (U) edge[geldstrom] node[above right] {8} (A);
    \draw (A) edge[geldstrom] node[right] {17} (S);
    \draw (S) edge[geldstrom] node[right] {14} (A);
    \draw (S) edge[geldstrom] node[below right] {15} (U);
    \draw (U) edge[geldstrom] node[below right] {5} (S);
    \end{scope}
    \begin{scope}[inner sep=6pt,pos=0.78]
    \draw (H) edge[bend right=22,bendstrom] node[below left] {4} (A);
    \draw (A) edge[bend left=22,bendstrom] node[below left] {20} (H);
    \draw (B) edge[bend left=22,bendstrom] node[above left] {11} (S);
    \draw (S) edge[bend right=22,bendstrom] node[above left] {16} (B);
    \end{scope}
  \end{tikzpicture}
\end{document}

enter image description here

EDIT: Simplified the code, moved the annotations in such a way that the graph becomes less busy, and stole the arrows from @Zarko's answer.

  • Original, bravo ! – Tarass Mar 27 '18 at 12:49
5

Base on @marmot's idea, to avoid maximum crossings :

enter image description here

\documentclass[parskip=half]{scrreprt}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}

\pagestyle{empty}
\usetikzlibrary{arrows.meta,positioning,shapes,decorations.markings}
\tikzset{subjekt/.style={rectangle,draw,minimum height=.7cm, minimum width=2.5cm, align=center},
         strom/.style={line width=3pt, shorten >=2pt,shorten <=2pt},
         gueterstrom/.style={strom,Goldenrod,->},
         geldstrom/.style={strom,SlateGrey,-,
         postaction={decoration={markings,
            mark=at position 0.7 with {\arrow[shorten >=0pt,shorten <=0pt,->]
            {>}}},decorate}},
         bendstrom/.style={strom,SlateGrey,-,
         postaction={decoration={markings,
            mark=at position 0.72 with {\arrow[shorten >=0pt,shorten <=0pt,->]
            {>}}},decorate}}}
\begin{document}
  \begin{tikzpicture}[node distance=5cm,>=Stealth]
    \node[subjekt] (H) at (-1.5,3.5) {Haushalt};
    \node[subjekt] (U) at (2,0) {Unternehmen};
    \node[subjekt] (S) at (5,5) {Staat};
    \node[subjekt] (B) at (-1.5,-3.5)  {Banken};
    \node[subjekt] (A) at (5,-5) {Ausland};
    \begin{scope}[inner sep=6pt,pos=0.68]
    \draw (H) edge[geldstrom] node[left] {3} (B);
    \draw (B) edge[geldstrom] node[left] {9} (H);
    \draw (H) edge[geldstrom] node[above] {1} (S);
    \draw (S) edge[geldstrom] node[above] {13} (H);
    \draw (H) edge[geldstrom] node[above right] {2} (U);
    \draw (U) edge[geldstrom] node[above right] {6} (H);
    \draw (B) edge[geldstrom] node[below right] {10} (U);
    \draw (U) edge[geldstrom] node[below right] {7} (B);
    \draw (B) edge[geldstrom] node[below] {12} (A);
    \draw (A) edge[geldstrom] node[below] {19} (B);
    \draw (A) edge[geldstrom] node[above right] {18} (U);
    \draw (U) edge[geldstrom] node[above right] {8} (A);
    \draw (A) edge[geldstrom] node[right] {17} (S);
    \draw (S) edge[geldstrom] node[right] {14} (A);
    \draw (S) edge[geldstrom] node[below right] {15} (U);
    \draw (U) edge[geldstrom] node[below right] {5} (S);
    \end{scope}
    \begin{scope}[inner sep=6pt,pos=0.78]
    \draw (H) edge[bend right=80,bendstrom,looseness=1.7] node[below left] {4} (A);
    \draw (A) edge[bend left=80,bendstrom,looseness=1.7] node[below left] {20} (H);
    \draw (B) edge[bend left=80,bendstrom,looseness=1.7] node[above left] {11} (S);
    \draw (S) edge[bend right=80,bendstrom,looseness=1.7] node[above left] {16} (B);
    \end{scope}
  \end{tikzpicture}
\end{document}

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.