tikz 工作分解

tikz 工作分解

我需要改进工作分解,以灵活地定义章节、部分、小节和小小节之间的距离级别。非常感谢您的帮助。谢谢

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
\usetikzlibrary{shadows,trees}

\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center, fill=green!30},
 level 2/.style={sibling distance=4cm, level distance=4.5cm, basic, rounded corners=6pt, thin,align=center, fill=green!60, text width=8em},
  level 3/.style = {node distance = 5cm and 2cm, basic, thin, align=left, fill=pink!60, text width=5.5em},
 level 4/.style = {basic, thin, align=right, fill=pink!30, text width=6.5em},
 level 5/.style = {basic, thin, align=right, fill=green!30, text width=6.5em}
}

    \begin{document}


\begin{tikzpicture}[
level 1/.style={sibling distance=4cm, level distance=1.5cm},
  edge from parent/.style={->,draw},
  >=latex]

% niveau1
\node[root] {book}
% niveau2
  child {node[level 2] (c1) {chapter 1}}
  child {node[level 2] (c2) {chapter 2}}
  child {node[level 2] (c3) {chapter3}}
  child {node[level 2] (c4) {chapter4}};

% section chapitre1
\begin{scope}[every node/.style={level 3}]
\node [below of = c1, xshift=15pt, yshift=0pt] (c11) {Section};
\node [below of = c11] (c12) {Section};
\node [below of = c12] (c13) {Section};

% section chapitre2
\node [below of = c2, xshift=15pt, yshift=0pt] (c21) {Section};
\node [below of = c21] (c22) {Section};
\node [below of = c22] (c23) {Section};
\node [below of = c23] (c24) {Section};

% Subsection chapitre2
\begin{scope}[every node/.style={level 4}]
\node [below right of = c21, xshift=5pt, yshift=-7pt] (c211) {Subsection};
\node [below of = c211] (c212) {Subsection};
\node [below of = c212] (c213) {Subsection};
\node [below of = c213] (c214) {Subsection};

\node [below right of = c22, xshift=5pt, yshift=0pt] (c221) {Subsection};
\node [below of = c221] (c222) {Subsection};
\node [below of = c222] (c223) {Subsection};
\node [below of = c223] (c224) {Subsection};
 level 4/.style = {basic, thin, align=right, fill=pink!30, text width=6.5em}
\end{scope}

% Subsubsection chapitre2
\begin{scope}[every node/.style={level 5}]
\node [below right of = c211, xshift=5pt, yshift=-7pt] (c2111) {Subsubsection};
\node [below of = c2111] (c2112) {Subsubsection};
\end{scope}


% section chapitre3
\node [below of = c3, xshift=15pt, yshift=0pt] (c31) {Section};
\node [below of = c31] (c32) {Section};
\node [below of = c32] (c33) {Section};


% section chapitre4
\node [below of = c4, xshift=15pt, yshift=0pt] (c41) {Section};
\node [below of = c41] (c42) {Section};
\node [below of = c42] (c43) {Section};
\node [below of = c43] (c44) {Section};
\node [below of = c44] (c45) {Section};
\end{scope}



% lines from each level 1 node to every one of its "children"
\foreach \value in {1,2,3}
  \draw[->] (c1.195) |- (c1\value.west);

\foreach \value in {1,...,4}
  \draw[->] (c2.195) |- (c2\value.west);

\foreach \value in {1,...,3}
  \draw[->] (c3.195) |- (c3\value.west);

\foreach \value in {1,...,5}
  \draw[->] (c4.195) |- (c4\value.west);

\foreach \value in {1,...,4}
  \draw[->] (c21.195) |- (c21\value.west);


\end{tikzpicture}
\end{document}

答案1

除了图表的顶部,您不是将结构绘制为树状图,而是手动放置节点,这绝不是一个非常灵活的解决方案。使用任何树状图绘制方法(内置、库等trees)都将使代码更灵活、更简洁且更易于维护。tikz-qtreeforest

如果可以选择 Forest,您可以允许包在大多数情况下自动布局树。Forest 在构建紧凑的树方面做得很好,可以避免重叠,同时最大限度地减少空白。该edgesfolder为树的主体提供了一种样式,可以通过 自动应用样式level。请注意,在这种情况下,根节点位于零级,章节位于一级。这也意味着可以非常简洁地指定树。

以下是一个例子:

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{shadows}
\tikzset{% note the change to the level numbering: root -> level 0, level 2 -> level 1 etc.
  basic/.style = {draw, text width=2cm, drop shadow, font=\sffamily},
  level 0/.style = {basic, rounded corners=2pt, thin, align=center, fill=green!30},
  level 1/.style={basic, rounded corners=6pt, thin,align=center, fill=green!60, text width=8em},
  level 2/.style = {basic, thin, align=left, fill=pink!60, text width=5.5em},
  level 3/.style = {basic, thin, align=right, fill=pink!30, text width=6.5em},
  level 4/.style = {basic, thin, align=right, fill=green!30, text width=6.5em}
}
\begin{document}
\begin{forest}
  where level>=1{folder, grow'=0, fit=band}{},
  for tree={
    node options/.process={Ow{level}{level #1}},
    s sep'+=5pt,
  },
  [book
    [chapter 1
      [Section] [Section] [Section]
    ]
    [chapter 2
      [Section
        [Subsection
          [Subsubsection]
          [Subsubsection]
        ]
        [Subsection]
        [Subsection]
        [Subsection]
     ] 
      [Section
        [Subsection]
        [Subsection]
        [Subsection]
        [Subsection]
      ] 
      [Section] 
      [Section]
    ]
    [chapter 3
      [Section] [Section] [Section]
    ]
    [chapter 4
      [Section] [Section] [Section] [Section] [Section]
    ]
  ]
\end{forest}
\end{document}

森林版

相关内容