TikZ 树中的间距?

TikZ 树中的间距?

我已经创建了工作分解结构,但在划分层级以使其不重叠方面遇到了麻烦。这是我的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
\usepackage[none]{hyphenat}
\usetikzlibrary{shadows,trees}


\begin{document}
\hspace{-140pt}
    \begin{tikzpicture}[
      every node/.style = {draw, rounded corners=3pt, semithick, drop shadow},
            ROOT/.style = {fill=blue!20, inner sep=2mm, font=\bfseries},
              L1/.style = {fill=blue!20},
              L2/.style = {fill=orange!30, sibling distance=50mm},
              L3/.style = {fill=green!90},
              L4/.style = {fill=green!40, grow=down, xshift=-0.9em, anchor=west, edge from parent path={(\tikzparentnode.west) |- (\tikzchildnode.west)}},
              L5/.style = {fill=green!10, grow=down, xshift=-0.9em, anchor=west, edge from parent path={(\tikzparentnode.west) |- (\tikzchildnode.west)}},
edge from parent/.style = {draw, thick},
              LD/.style = {level distance=#1ex},
             LD1/.style = {level distance=8ex},
             LD2/.style = {level distance=16ex},
             LD3/.style = {level distance=24ex},
             LD4/.style = {level distance=32ex},
             LD5/.style = {level distance=40ex},
             LD6/.style = {level distance=48ex},
             LD7/.style = {level distance=56ex},
             LD8/.style = {level distance=64ex},
             LD9/.style = {level distance=72ex},
             LD10/.style = {level distance=80ex},
             LD11/.style = {level distance=88ex},
             LD12/.style = {level distance=96ex},
         level 1/.style = {sibling distance=35mm},
                        ]
    % Parents
\node[ROOT] {1 M-C19}
    [edge from parent fork down]
    child{node[L2] {1.1 Vehicle}
      [edge from parent fork down]
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.1 \\Fuselage\\ \end{tabular}}
        child[L4,LD1]   {node[L4]   {\begin{tabular}{l} 1.1.1.1 \\Cockpit\\ \end{tabular}}
          child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.1.1.1\\Instruments\\ \end{tabular}}}
          child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.1.1.2\\Seats\\ \end{tabular}}}
        }
        child[L4,LD4]   {node[L4]   {\begin{tabular}{l} 1.1.1.2 \\Body\\ \end{tabular}}
           child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.1\\Cargo holdings\\ \end{tabular}}}
           child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.2\\Seats\\ \end{tabular}}}
           child[L5,LD3]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.3\\W.C. \\ \end{tabular}}}
           child[L5,LD=33.5]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.4\\Onboard \\comfort system\\ \end{tabular}}}
           child[L5,LD=43]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.5\\Cargo loading\\ \end{tabular}}}
           child[L5,LD=51]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.6\\Doors\\ \end{tabular}}}
           child[L5,LD=59]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.7\\Body shell\\ \end{tabular}}}
        }
      }
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.2 \\Wing\\ \end{tabular}}
        child[L4,LD1]   {node[L4]   {\begin{tabular}{l} 1.1.2.1 \\Wing body\\ \end{tabular}}
           child[L5,LD=9.5]   {node[L5]   {\begin{tabular}{l} 1.1.2.1.1\\Structural\\ analysis\\ \end{tabular}}}
           child[L5,LD=20.5]   {node[L5]   {\begin{tabular}{l} 1.1.2.1.2\\Aerodynamic\\ analysis\\ \end{tabular}}}
        }
        child[L4,LD5]   {node[L4]   {\begin{tabular}{l} 1.1.2.2 \\Auxiliar elements\\ \end{tabular}}
           child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.1\\Flaps\\ \end{tabular}}}
           child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.2\\Ailerons\\ \end{tabular}}}
           child[L5,LD3]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.3\\Winglets \\ \end{tabular}}}
           child[L5,LD4]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.4\\Slats\\ \end{tabular}}}
           child[L5,LD5]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.5\\Stall system analysis\\ \end{tabular}}}
        }
        child[L4,LD11]   {node[L4]   {\begin{tabular}{l} 1.1.2.3 \\Wing unions\\ \end{tabular}}
           child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.2.3.1\\Fuselage-wing\\ \end{tabular}}}
           child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.2.3.2\\Engine-wing\\ \end{tabular}}}
        }
      }
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.3 \\Tail\\ \end{tabular}}
        child[L5,LD=9.5]   {node[L5]   {\begin{tabular}{l} 1.1.3.1 \\Horizontal \\stabilizer\\ \end{tabular}}}
        child[L5,LD=20.5]   {node[L5]   {\begin{tabular}{l} 1.1.3.2 \\Vertical \\stabilizer\\ \end{tabular}}}
      }
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.4 \\Engine\\ \end{tabular}}}
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.5 \\Landing gear\\ \end{tabular}}}
      }
    child{node[L2] {1.2 Project Management}
      child[L5,LD1]  {node[L5]   {B1}}
      child[L5,LD2]  {node[L5]   {B2}}
            }
\end{tikzpicture}
\end{document}

答案1

这是一个以非常临时的方式修复问题的版本。但是我没有尝试清理代码。特别是,我没有消除节点样式的重复。如果你公开代码的来源,我很乐意在这方面投入更多精力。更可能的情况是,切换到森林会更有效率。

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
\usepackage[none]{hyphenat}
\usetikzlibrary{shadows,trees}


\begin{document}
%\hspace{-140pt}
    \begin{tikzpicture}[
      every node/.style = {draw, rounded corners=3pt, semithick, drop shadow},
            ROOT/.style = {fill=blue!20, inner sep=2mm, font=\bfseries},
              L1/.style = {fill=blue!20},
              L2/.style = {fill=orange!30, sibling distance=50mm},
              L3/.style = {fill=green!90},
              L4/.style = {fill=green!40, grow=down, xshift=-0.9em, anchor=west, edge from parent path={(\tikzparentnode.west) |- (\tikzchildnode.west)}},
              L5/.style = {fill=green!10, grow=down, xshift=-0.9em, anchor=west, edge from parent path={(\tikzparentnode.west) |- (\tikzchildnode.west)}},
edge from parent/.style = {draw, thick},
              LD/.style = {level distance=#1ex},
             LD1/.style = {level distance=8ex},
             LD2/.style = {level distance=16ex},
             LD3/.style = {level distance=24ex},
             LD4/.style = {level distance=32ex},
             LD5/.style = {level distance=40ex},
             LD6/.style = {level distance=48ex},
             LD7/.style = {level distance=56ex},
             LD8/.style = {level distance=64ex},
             LD9/.style = {level distance=72ex},
             LD10/.style = {level distance=80ex},
             LD11/.style = {level distance=88ex},
             LD12/.style = {level distance=96ex},
         level 1/.style = {sibling distance=35mm},
                        ]
    % Parents
\node[ROOT] {1 M-C19}
    [edge from parent fork down]
    child{node[L2] {1.1 Vehicle}
      [edge from parent fork down]
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.1 \\Fuselage\\ \end{tabular}}
        child[L4,LD1]   {node[L4]   {\begin{tabular}{l} 1.1.1.1 \\Cockpit\\ \end{tabular}}
          child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.1.1.1\\Instruments\\ \end{tabular}}}
          child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.1.1.2\\Seats\\ \end{tabular}}}
        }
        child[L4,LD4]   {node[L4]   {\begin{tabular}{l} 1.1.1.2 \\Body\\ \end{tabular}}
           child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.1\\Cargo holdings\\ \end{tabular}}}
           child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.2\\Seats\\ \end{tabular}}}
           child[L5,LD3]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.3\\W.C. \\ \end{tabular}}}
           child[L5,LD=33.5]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.4\\Onboard \\comfort system\\ \end{tabular}}}
           child[L5,LD=43]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.5\\Cargo loading\\ \end{tabular}}}
           child[L5,LD=51]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.6\\Doors\\ \end{tabular}}}
           child[L5,LD=59]   {node[L5]   {\begin{tabular}{l} 1.1.1.2.7\\Body shell\\ \end{tabular}}}
        }
      }
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.2 \\Wing\\ \end{tabular}}
        child[L4,LD1]   {node[L4]   {\begin{tabular}{l} 1.1.2.1 \\Wing body\\ \end{tabular}}
           child[L5,LD=9.5]   {node[L5]   {\begin{tabular}{l} 1.1.2.1.1\\Structural\\ analysis\\ \end{tabular}}}
           child[L5,LD=20.5]   {node[L5]   {\begin{tabular}{l} 1.1.2.1.2\\Aerodynamic\\ analysis\\ \end{tabular}}}
        }
        child[L4,LD5]   {node[L4]   {\begin{tabular}{l} 1.1.2.2 \\Auxiliar elements\\ \end{tabular}}
           child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.1\\Flaps\\ \end{tabular}}}
           child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.2\\Ailerons\\ \end{tabular}}}
           child[L5,LD3]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.3\\Winglets \\ \end{tabular}}}
           child[L5,LD4]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.4\\Slats\\ \end{tabular}}}
           child[L5,LD5]   {node[L5]   {\begin{tabular}{l} 1.1.2.2.5\\Stall system analysis\\ \end{tabular}}}
        }
        child[L4,LD11]   {node[L4]   {\begin{tabular}{l} 1.1.2.3 \\Wing unions\\ \end{tabular}}
           child[L5,LD1]   {node[L5]   {\begin{tabular}{l} 1.1.2.3.1\\Fuselage-wing\\ \end{tabular}}}
           child[L5,LD2]   {node[L5]   {\begin{tabular}{l} 1.1.2.3.2\\Engine-wing\\ \end{tabular}}}
        }
      }
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.3 \\Tail\\ \end{tabular}}
        child[L5,LD=9.5]   {node[L5]   {\begin{tabular}{l} 1.1.3.1 \\Horizontal \\stabilizer\\ \end{tabular}}}
        child[L5,LD=20.5]   {node[L5]   {\begin{tabular}{l} 1.1.3.2 \\Vertical \\stabilizer\\ \end{tabular}}}
      }
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.4 \\Engine\\ \end{tabular}}}
      child[L3,LD1]   {node[L3]   {\begin{tabular}{l} 1.1.5 \\Landing gear\\ \end{tabular}}}
      }
    child{node[L2] (PM) {1.2 Project Management}
            };
    \node[right=1cm of PM,L5] (B2)  {B2};
    \node[above=5mm of B2,L5] (B1)  {B1};
    \draw[thick] (PM) -- (B2) coordinate[midway] (aux);
    \draw[thick] (aux) |- (B1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容