編輯

編輯

大約一周前@cfr已經提供了一個非常好的解決方案在我的樹圖中節省垂直空間。不幸的是,我最初的情況現在發生了變化,我面對的是一棵超出我能力的水平樹。實際上,它與我上一個問題中的樹是同一棵樹,不同之處在於三個主要分支之一現在是剩餘兩個主要分支的一部分。這是我嘗試過的:

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

水平樹

由於某些原因,帶有換行符的節點不能很好地對齊...有人可以解釋為什麼或我如何解決這個問題嗎?

有沒有辦法只分離出一層的一個節點?在範例中,節點「Technische Rahmenbedinungen」應向右分割 2 公分。s sep只適用於整個關卡...

最後但並非最不重要的一點是,有人知道如何在這裡節省更多的水平空間嗎?文字還是有點太小了。

我也這麼做了,這當然是一個很好的選擇,但水平方向讓我感到困惑:

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

垂直樹

我很感激任何幫助!

答案1

添加

anchor=parent,

對於樹將確保節點對齊更整齊:

更整齊的對齊

要移動特定節點,您可以新增

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

對於有問題的節點。例如:

節點右移

如果您希望它也適用於節點的後代,您可以為整個子樹添加它。例如:

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

子樹右移

當然,這顯然會佔用樹中更多的水平空間,而樹看起來已經分佈得很不舒服了。 (為什麼需要向右移動2cm嗎?無論這代表什麼,它可以用另一種方​​式代表嗎?

很難知道對於水平空間有什麼建議。最明顯的建議是不要做你正在做的事情增加水平空間,例如即使text width對於不需要太多空間的節點也使用統一的空間。而設置s sep=3cm顯然進一步增加了水平空間的利用。

如果你可以犧牲這些限制,你可以這樣做:

重新排列的樹

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

編輯

上面的內容對我來說效果很好\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}

調整大小

添加calign with currentAnpassbarkeit

          [Anpassbarkeit, calign with current]

產生

重新調整

相關內容