[Tex/LaTex] Saving vertical space in tree diagram

diagramsforesttrees

I have many nodes on one tier. Thus I use the grow east option already. But this is not enough… I would like to save a bit more vertical space for instance through pulling two of the branches a little bit to the right. Or maybe pulling out the middle one would look even better…

Is there an option for extending the horizontal lines? Or does someone has a different idea how to save vertical space excep reducing the size? 🙂

big tree

Here my code:

\documentclass[ngerman]{scrreprt}
\usepackage[edges]{forest}
\usepackage{tikz}
\usetikzlibrary{trees}

%Defining tikz classes for tree diagrams
\tikzset{parent/.style={align=center,text width=3cm,rounded corners=3pt},
    child/.style={align=center,text width=3cm,rounded corners=3pt}
    }

\begin{document}

    \begin{center}
        \resizebox{.7\textwidth}{!}{%
            \begin{forest}
                for tree={
                    grow'=east,
                    forked edges,
                    draw,
                    rounded corners,
                    node options={
                        align=center },
                    text width=2.7cm,
                    anchor=west,
                }
                [LMS, fill=gray!25, parent
                [Funktionale \\Anforderungen, for tree={fill=brown!25, child}
                [Lerninhalte organisieren]
                [Lerninhalte erstellen]
                [Lerninhalte abfragen]
                [Kommunikation]
                [Benutzerkonten\-führung]
                [Steuerungs\-funktionen]
                ]
                [Nicht-Funktionale Anforderungen, for tree={fill=red!25,child}
                [Zuverl{\"a}ssig\-keit]
                [Skalierbar\-keit und Effizienz]
                [Benutzer\-freundlich\-keit]
                [Portierbarkeit]
                [Datenschutz / Informationssicherheit]
                [Erweiterbar\-keit]
                [Anpassbarkeit]
                ]
                [Technische Rahmen\-bedinungen, for tree={fill=blue!25, child}
                [System\-architektur]
                [Software\-kriterien]
                [Schnittstellen]
                [Wartung und Support
                [Support\-leistungen]
                [Software-Pflege]
                ]
                ]     
                ]
            \end{forest}    
        }
    \end{center}


\end{document}

Best Answer

I don't know if this is helpful but, as a follow up to discussion in comments, you might make the tree more generally compact by doing something like this:

\documentclass[ngerman]{scrreprt}
\usepackage[edges]{forest}
\tikzset{%
  parent/.style={align=center,text width=3cm,rounded corners=3pt},
  child/.style={align=center,text width=3cm,rounded corners=3pt}
}
\begin{document}
\begin{center}
  \resizebox{.7\textwidth}{!}{%
    \begin{forest}
      for tree={
        % forked edges,
        draw,
        rounded corners,
        node options={align=center,},
        text width=2.7cm,
      },
      where level=0{%
      }{%
        folder,
        grow'=0,
        if level=1{%
          before typesetting nodes={child anchor=north},
          edge path'={(!u.parent anchor) -- ++(0,-5pt) -| (.child anchor)},
        }{},
      }
      [LMS, fill=gray!25, parent
      [Funktionale \\Anforderungen, for tree={fill=brown!25, child}
      [Lerninhalte organisieren]
      [Lerninhalte erstellen]
      [Lerninhalte abfragen]
      [Kommunikation]
      [Benutzerkonten\-führung]
      [Steuerungs\-funktionen]
      ]
      [Nicht-Funktionale Anforderungen, for tree={fill=red!25,child}
      [Zuverl{\"a}ssig\-keit]
      [Skalierbar\-keit und Effizienz]
      [Benutzer\-freundlich\-keit]
      [Portierbarkeit]
      [Datenschutz / Informationssicherheit]
      [Erweiterbar\-keit]
      [Anpassbarkeit]
      ]
      [Technische Rahmen\-bedinungen, for tree={fill=blue!25, child}
      [System\-architektur]
      [Software\-kriterien]
      [Schnittstellen]
      [Wartung und Support
      [Support\-leistungen]
      [Software-Pflege]
      ]
      ]
      ]
    \end{forest}
  }
\end{center}
\end{document}

compact tree

Note that resizing graphics which contain text is not recommended as you end up with a motley of different font sizes. So, if you can avoid resizing the box like that, it would be preferable.

EDIT

To address the queries in comments:

  1. 'Centre' is actually ambiguous - centre relative to what? I would recommend aligning the root with the middle child. The easiest way to do this is probably to add calign with current edge to the relevant child node:

    [Nicht-Funktionale Anforderungen, for tree={fill=red!25,child}, calign with current edge
    

which gives

align root

The edges are being controlled in multiple ways:

  • forked edges applies to the entire tree (although it is not actually doing anything as it is being overridden in all cases);
  • folder changes the edges for all nodes below the root, which is to say, all nodes which can possibly have edges;
  • edge path' then makes a final change for the nodes in the first level only, which are the edges you were trying to change.

So to revert to the default style for the first level, we want to:

  • delete forked edges;
  • delete edge path.

folder doesn't harm anything here, so we can just leave that:

diagonals to level 1

If we wanted the edges to begin from a common point, we could redefine parent anchor for the root:

  where level=0{%
    parent anchor=children,
  }{%

diagonals from common point

or we could use an alternative definition of edge path of whatever kind we wanted. For example:

  where level=0{%
    parent anchor=children,
  }{%
    folder,
    grow'=0,
    if level=1{%
      before typesetting nodes={child anchor=north},
      edge path'={%
        (!u.parent anchor) -- ++(0,-5pt) -- (.child anchor)
      },
    }{},
  }

alternate edge path

Related Question