6

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}
Eric
  • 683

2 Answers2

8

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

cfr
  • 198,882
  • I really like this! – Eric Mar 17 '16 at 15:54
  • I got to correct myself, this is awesome! – Eric Mar 17 '16 at 16:12
  • @Eric I think folder is rather misleading as a name for this as it makes me think it is about what the nodes look like, rather than the structure of the tree. But it makes it much easier than it was to do this in version 1. – cfr Mar 18 '16 at 21:30
  • Do you know if it is possible to center the root node? – Eric Mar 19 '16 at 17:45
  • 1
    I think I could make it with calign=fixed edge angles, calign primary angle=-80,calign secondary angle=80,. Please correct me if this is nonsense. – Eric Mar 19 '16 at 18:12
  • another point, just for my learning process: I tried to change the level0 to level1 connection directly (diagonal). Actually I thought this could be done by commenting out forked edges but it doesn't. Is there a quick trick? – Eric Mar 19 '16 at 18:18
  • 1
    @Eric Does this help? forked edges isn't actually doing anything, I don't think, so removing it makes no odds.... – cfr Mar 19 '16 at 23:04
  • Thanks alot for your detailled explanation! This definitely makes much more clear. Just one thing regarding your first point to calign with current edge: I can't use this when I have an even number of nodes. Is there another easier way than the one I mentioned above by setting the angles? – Eric Mar 20 '16 at 12:16
  • @Eric I don't think so. If that works, that seems probably easiest. Or you can use midpoint but then you need to set the primary and secondary children appropriately, which might have other effects. – cfr Mar 20 '16 at 13:49
5

You could align the nodes on the next level with tier=<some name>:

% arara: pdflatex

\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{figure}\centering
    \begin{forest}
        for tree={%
            ,scale=.78
            ,grow'=east
            ,forked edges
            ,draw
            ,rounded corners
            ,node options={align=center}
            ,text width=2.7cm
            ,anchor=west
            }
        [LMS, fill=gray!25, parent
            [Funktionale \\Anforderungen, tier=align here, 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, tier=align here]
            ]
            [Technische Rahmen\-bedinungen, tier=align here, for tree={fill=blue!25, child}
                [System\-architektur]
                [Software\-kriterien]
                [Schnittstellen]
                [Wartung und Support
                    [Support\-leistungen]
                    [Software-Pflege]
                ]
            ]     
        ]
    \end{forest}    
\end{figure}    
\end{document}

enter image description here

LaRiFaRi
  • 43,807
  • that's quite an option. Is there also a way to align the branches surrounding the root node LMS? – Eric Mar 15 '16 at 16:45
  • @Eric Sorry, I do not understand. Do you want to get the two branches I just pushed down for one level to be pulled up two levels? This would need some reordering of the whole [[[]]] system which you could do by your self, I guess. You could align Nicht-Funktionale Anforderungen with e.g. Steuerungsfunktionen then. However it would be difficult to show that this is a tree then, if there is no growth to the right of LMS. Maybe you should redesign the whole thing to "top-down" or you get rid of the first level "LMS" and describe it in \caption{Three childs of LMS} or alike. – LaRiFaRi Mar 15 '16 at 16:50
  • I mean is there a way to get rid of the grow east and archieve some space by positioning Funktionale Anforderungen on the upper left hand side of LMS and Technische Rahmenbedingungen on the lower left hand side of LMS. So LMS would be in the center, two branches on the left hand side and one on the right hand side, you know? – Eric Mar 15 '16 at 16:59
  • 2
    @Eric I'm not really clear what you mean. The children of Funk. Anf. would then end up growing down over Tech. Rah., wouldn't they? If you use something like TikZ trees, you can have cyclical growth, but Forest doesn't support that. You can't have e.g. one child growing north and another south if they are children of the same parent. (You can fake it using separate trees, but it requires manual adjustments.) – cfr Mar 17 '16 at 13:28
  • @Eric What about using the directory style offered by Forest now? – cfr Mar 17 '16 at 13:30
  • @cfr maybe I consider trying to archieve this with TikZ next time. For now I really like your suggestion below! – Eric Mar 17 '16 at 15:57