[Tex/LaTex] Problems with flow chart – decision tree

flow chartstikz-arrowstikz-pgftikz-stylestikz-trees

I am creating a decision tree with flow chart in the using the tikz-package. A MWE is as follow:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\newdimen\nodeDist
\nodeDist=35mm
\begin{document}
\pagestyle{empty}
\tikzstyle{block} = [rectangle, draw, fill=white!20,
    text width=10em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, very thick, color=black!50, -latex']
\begin{tikzpicture}[
    node/.style={%
      draw,
         },
  ]
    \node [node] (A) {Both HF and LF waves important?};
    \path (A) ++(-135:\nodeDist) node [node] (B) {Phase averaged};
    \path (B) ++(-90:\nodeDist) node [node] (I) {nonlinearity?};
    \path (A) ++(-45:\nodeDist) node [node] (C) {Phase resolving};
    \path (C) ++(-90:\nodeDist) node [node] (D) {Is it complex?};
    \path (D) ++(-90:\nodeDist) node [node] (E) {Spectral?};
    \path (E) ++(-45:\nodeDist) node [node] (F) {NH, Boussinesq};
    \path (E) ++(-135:\nodeDist) node [node] (G) {Large gradient?};
    \path (G) ++(-45:\nodeDist) node [node] (H) {mild slope};
    \path (I) ++(-135:\nodeDist) node [node] (J) {SWE + groups};
    \path (I) ++(-45:\nodeDist) node [node] (K) {energies};
    
    \draw (A) -- (B) node [left,pos=0.25] {no}(A);
    \draw (A) -- (C) node [right,pos=0.25] {yes}(A);
    \draw (D) -- (E) node [right , pos = 0.25]{yes/no} (D);
    \draw (E) -- (F) node [right, pos = 0.25]{yes} (E);
    \draw (E) -- (G) node [left, pos = 0.25]{no} (E);
    \draw (G) -- (F) node [above, pos = 0.5]{yes} (G);
    \draw (G) -- (H) node [right, pos=0.25]{no} (G);
    \draw (D) -- (I) node [above , pos = 0.5]{no*} (D);
    \draw (I) -- (J) node [left, pos = 0.25]{yes} (I);
    \draw (I) -- (K) node [right, pos = 0.25]{no} (I);
    \draw (B) -- (I);
    \draw (C) -- (D) ;
\end{tikzpicture}
\end{document}

which looks like this:
enter image description here

The problems associated with this decision tree are:

  • there are no arrows from one path (node) to another.
  • the blocks (or nodes) does not have rounded corners as I have defined.
  • the decision tree looks a little bit clumsy, I do not like the diagonal lines. I prefer straight lines.
  • The end of the left part (phase averaged) does not have the same 'ending height' as the 'phase-resolving' part.

Preferably, I would like to have something that looks like this (more organised, less clumsy):

enter image description here

I am already stuck on it for a while. How to proceed further?

Best Answer

I don't understand all the desiderata. I also don't know if an alternative approach is an option. But, for whatever it is worth, here's a forest solution.

This satisfies the first 3 desiderata, in addition to applying the defined styles correctly. Whether it satisfies the fourth of the desiderata I cannot say. Since I don't understand that one, if it satisfies it, it does so purely by accident. If not, that is entirely to be expected.

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}% arrows is deprecated
\begin{document}
\tikzset{% \tikzstyle is deprecated
  block/.style={rectangle, draw, fill=white!20, text width=10em, text centered, rounded corners, minimum height=4em},
  line/.style={draw, very thick, color=black!50, -Stealth},
}
\begin{forest}
  arrow to/.style n args=2{%
    delay={%
      tikz+={%
        \draw [every edge, line] () -- (!#1) node [above, midway] {#2};
      },
    },
    !u.s sep+=30pt,
  },
  before typesetting nodes={%
    where n=1{%
      edge label/.wrap value={%
        node [left,pos=.75, anchor=mid east] {#1}
      },
    }{%
      edge label/.wrap value={%
        node [right,pos=.75, anchor=mid west] {#1}
      },
    },
  },
  for tree={%
    parent anchor=children,
    child anchor=parent,
    block,
    edge={line},
    l sep+=10pt,
  },
  forked edges
  [Both HF and LF waves important?
    [Phase averaged, edge label=no
      [nonlinearity?
        [SWE + groups, edge label=yes
        ]
        [energies, edge label=no
        ]
      ]
    ]
    [Phase resolving, edge label=yes
      [Is it complex?, arrow to={us1}{no*}
        [Spectral?, edge label={yes/no}
          [Large gradient?, edge label=no
            [, phantom
            ]
            [mild slope, edge label=no
            ]
          ]
          [{NH, Boussinesq}, edge label=yes, arrow to={s}{yes}
          ]
        ]
      ]
    ]
  ]
\end{forest}    
\end{document}

forest solution