[Tex/LaTex] saving horizontal space in tree diagram

diagramsforesttrees

About a week ago @cfr already provided a very decent solution for saving vertical space in my tree diagram. Unfortunately my initial situation has changed now and I am facing a horizontal tree which exceeds my skills. Actually it is the same tree as in my previous question, with the difference that one of the three main branches is now part of the two remaining main branches. Here is what I have tried:

\documentclass[a4paper,11pt]{article}
\usepackage[edges]{forest}

%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}
}

\colorlet{col1}{white}
\colorlet{col2}{gray!20}
\colorlet{col3}{gray!40}
\colorlet{col4}{gray!60}

\begin{document}
    \begin{center}
        \resizebox{\linewidth}{!}{%
        \begin{forest}
            forked edges,
            for tree={
                draw,
                rounded corners,
                node options={align=center,},
                text width=2.7cm,
                minimum height=1.5cm,
                parent anchor=children,
            }
            [LMS, fill=col4, parent, s sep=3cm
            [Funktionale \\Anforderungen, for tree={child, fill=col3}
            [Lerninhalte organisieren, tier=first]
            [Lerninhalte erstellen]
            [Lerninhalte abfragen]
            [Kommunikation]
            [Benutzerkonten\-führung]
            [Steuerungs\-funktionen]
            ]
            [Nicht-Funktionale Anforderungen, tier=first, for tree={child, fill=col2}
            [Zuverl{\"a}ssig\-keit]
            [Skalierbar\-keit und Effizienz]
            [Benutzer\-freundlich\-keit]
            [Portierbarkeit]
            [Datenschutz / Informationssicherheit]
            [Erweiterbar\-keit]
            [Anpassbarkeit]
            [Technische Rahmen\-bedinungen, for tree={child, calign=last, fill=col1}
            [System\-architektur]
            [Software\-kriterien]
            [Schnittstellen]
            [Wartung und Support
            [Support\-leistungen]
            [Software-Pflege]
            ]
            ]
            ]
            ]
        \end{forest}
    }
\end{center}
\end{document}

horizontal tree

For some reasons the nodes with a linebreak doesn't align well… Can somebody explain why or rather how I can fix this?

And is there a way to split off only one node of one level? In the example the node "Technische Rahmenbedinungen" should be splitted to the right by 2cm. s sep just applies for an entire level…

Last but not least, has anyone an idea how to save even a bit more of horizontal space here? The text is still a little bit too small.

I also did this, which of course is quite a good alternative but the horizontal teases me:

    \documentclass[a4paper,11pt,ngerman]{article}
    \usepackage[edges]{forest}
    \usepackage{caption}

    %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}
    }

    \colorlet{col1}{white}
    \colorlet{col2}{gray!20}
    \colorlet{col3}{gray!40}
    \colorlet{col4}{gray!60}

    \begin{document}
        \begin{center}
            \resizebox*{.75\linewidth}{!}{%
                \begin{forest}
                    forked edges,
                    for tree={
                        grow'=east,
                        draw,
                        rounded corners,
                        text width=2.7cm,
                        node options={align=center},
                    }       
                    [LMS, fill=col4, parent, s sep=1cm
                    [Funktionale \\Anforderungen, for tree={child, fill=col3}
                    [Lerninhalte organisieren]
                    [Lerninhalte erstellen]
                    [Lerninhalte abfragen, calign with current]
                    [Kommunikation]
                    [Benutzerkonten\-führung]
                    [Steuerungs\-funktionen]
                    ]
                    [Nicht-Funktionale Anforderungen, for tree={child, fill=col2}
                    [Zuverl{\"a}ssig\-keit]
                    [Skalierbar\-keit und Effizienz]
                    [Benutzer\-freundlich\-keit]
                    [Portierbarkeit]
                    [Datenschutz/\\Informations-\\sicherheit, calign with current]
                    [Erweiterbar\-keit]
                    [Anpassbarkeit]
                    [Technische Rahmen\-bedinungen, calign=last, for tree={child, fill=col1}
                    [System\-architektur]
                    [Software\-kriterien]
                    [Schnittstellen]
                    [Wartung und Support
                    [Support\-leistungen]
                    [Software-Pflege]
                    ]
                    ]
                    ]
                    ]
                \end{forest}}
                \captionsetup{type=figure}
                \captionof{figure}{Gliederung des UKSH Lastenheft: Subgliederung LMS}
                \label{abb:GliederungUKSHLMS}
            \end{center}
\end{document}

vertical tree

I appreciate any help!

Best Answer

Adding

anchor=parent,

for the tree will ensure that the nodes are aligned more neatly:

neater alignment

To move a particular node, you can add

before drawing tree={x'+=20mm}

for the node in question. For example:

shift node right

If you want it to apply to the node's descendants as well, you can add it for the entire sub-tree. For example:

[Technische Rahmen\-bedinungen, for tree={child, calign=last, fill=col1, before drawing tree={x'+=20mm}}

shift sub-tree right

Of course, this obviously uses more horizontal space in a tree which already looks as if it is spread rather uncomfortably. (Why does it need to go 2cm to the right? Whatever this represents, could it be represented in another way?)

It is hard to know what to suggest regarding the horizontal space. The most obvious suggestion is to not do the things you are doing to increase horizontal space, such as using a uniform text width even for nodes which do not require so much space. And setting s sep=3cm obviously increases the use of horizontal space further.

If you can sacrifice those constraints, you can do something like this:

rearranged tree

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage[edges]{forest}
%Defining tikz classes for tree diagrams
\forestset{%
  parent/.style={text width=3cm,rounded corners=3pt},
  child/.style={rounded corners=3pt},
  my phantom/.style={inner xsep=0pt, draw=none, child anchor=children}
}
\colorlet{col1}{white}
\colorlet{col2}{gray!20}
\colorlet{col3}{gray!40}
\colorlet{col4}{gray!60}

\begin{document}
\begin{forest}
    forked edges,
    for tree={
        draw,
        rounded corners,
        align=center,
        text centered,
        minimum height=1.5cm,
        parent anchor=children,
        anchor=parent,
    },
    before typesetting nodes={%
      where n children=0{}{%
        if content={}{}{%
          text width=27mm
        },
      },
    },
    [LMS, fill=col4, parent
      [Funktionale\\Anforderungen, for tree={child, fill=col3}
        [Lerninhalte\\organisieren, tier=first]
        [Lerninhalte\\erstellen]
        [Lerninhalte\\abfragen]
        [Kommunikation]
        [Benutzerkonten-\\führung]
        [Steuerungs-\\funktionen]
      ]
      [, tier=first, my phantom
        [Nicht-Funktionale\\Anforderungen, tier=second, for tree={child, fill=col2}
          [Zuverl{\"a}ssig\-keit, tier=third]
          [Skalierbar\-keit\\und Effizienz]
          [Benutzer-\\freundlich\-keit]
          [Portierbarkeit]
          [Datenschutz\\/ Informa-\\tionssicherheit]
          [Erweiterbar\-keit]
          [Anpassbarkeit]
          [, my phantom, tier=third
            [Technische\\Rahmen-\\bedinungen, for tree={child, calign=last, fill=col1}
              [System\-architektur]
              [Software\-kriterien]
              [Schnittstellen]
              [Wartung\\und Support
                [Support\-leistungen]
                [Software-Pflege]
              ]
            ]
          ]
        ]
      ]
    ]
\end{forest}
\end{document}

EDIT

The above works fine for me inside \resizebox...:

\documentclass{article}
\usepackage[edges]{forest}
%Defining tikz classes for tree diagrams
\forestset{%
  parent/.style={text width=3cm,rounded corners=3pt},
  child/.style={rounded corners=3pt},
  my phantom/.style={inner xsep=0pt, draw=none, child anchor=children}
}
\colorlet{col1}{white}
\colorlet{col2}{gray!20}
\colorlet{col3}{gray!40}
\colorlet{col4}{gray!60}

\begin{document}
  \resizebox*{\linewidth}{!}{%
\begin{forest}
    forked edges,
    for tree={
        draw,
        rounded corners,
        align=center,
        text centered,
        minimum height=1.5cm,
        parent anchor=children,
        anchor=parent,
    },
    before typesetting nodes={%
      where n children=0{}{%
        if content={}{}{%
          text width=27mm
        },
      },
    },
    [LMS, fill=col4, parent
      [Funktionale\\Anforderungen, for tree={child, fill=col3}
        [Lerninhalte\\organisieren, tier=first]
        [Lerninhalte\\erstellen]
        [Lerninhalte\\abfragen]
        [Kommunikation]
        [Benutzerkonten-\\führung]
        [Steuerungs-\\funktionen]
      ]
      [, tier=first, my phantom
        [Nicht-Funktionale\\Anforderungen, tier=second, for tree={child, fill=col2}
          [Zuverl{\"a}ssig\-keit, tier=third]
          [Skalierbar\-keit\\und Effizienz]
          [Benutzer-\\freundlich\-keit]
          [Portierbarkeit]
          [Datenschutz\\/ Informa-\\tionssicherheit]
          [Erweiterbar\-keit]
          [Anpassbarkeit]
          [, my phantom, tier=third
            [Technische\\Rahmen-\\bedinungen, for tree={child, calign=last, fill=col1}
              [System\-architektur]
              [Software\-kriterien]
              [Schnittstellen]
              [Wartung\\und Support
                [Support\-leistungen]
                [Software-Pflege]
              ]
            ]
          ]
        ]
      ]
    ]
  \end{forest}}
\end{document}

resized

Adding calign with current to Anpassbarkeit:

          [Anpassbarkeit, calign with current]

produces

realigned