8

I tried to follow TikZ-tree: edge-alignment in horizontal org-chart to make an org chart-like diagram like this enter image description here

I got stuck on making third-level down. Can you help in figuring this out?

I am not after making my new diagram looks exactly as the diagram above. As long the new one has everything in it then it is ok. My code is here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black,thick,anchor=west, minimum height=2.5em]

\begin{document}

\begin{figure}[!htb]
\resizebox{\linewidth}{!}{

\begin{tikzpicture}[
Models/.style={text centered, text width=3cm},
attribute/.style={%
grow=down, xshift=0cm,
text centered, text width=3cm,
edge from parent path={(\tikzparentnode.225) |- (\tikzchildnode.west)}},
first/.style    ={level distance=8ex},
second/.style   ={level distance=16ex},
third/.style    ={level distance=24ex},
fourth/.style   ={level distance=32ex},
fifth/.style    ={level distance=40ex},
level 1/.style={sibling distance=10em}]
    % Main Goal
\node[anchor=south]{Life Prediction Approaches and Techniques}
[edge from parent fork down]

% Criteria and Attributes
child{node (model1) [Models] {Model-base}
    child[attribute]  {node {Physics-of-Failure}}
    child[attribute,second] {node {Satistical Model}}
    child[attribute,third]  {node  {Kalman/Particle Filtering}}
    child[attribute,fourth] {node {Nonlinear Dynamics}}}
%
child{node [Models] {Knowledge-base}
    child[attribute,first]  {node {Expert Systems}}
    child[attribute,second] {node {Fuzzy Logics}}}
%
child{node [Models] {Experience-base}
    child[attribute,first]  {node {Parametric Distribution}}
    child[attribute,second] {node {Nonparametric Distribution}}}     
%
child{node [Models] {Data-driven}
    child[attribute,first]  {node {Multivariate Statistical Method}}
    child[attribute,second]  {node {Signal Analysis}}
    child[attribute,third]  {node {Graphics Model}}
    child[attribute,fourth]  {node {Self-Organizing Feature Map}}
    child[attribute,fifth] {node {Black-Box Method}}};
\end{tikzpicture}}
\caption{Life prediction approaches and techniques}
\end{figure}

\end{document}

Here the diagram for my code enter image description here

I also tried to make it in different way but I also got stuck. Here is my other code and diagram

\documentclass[a4paper,12pt,titlepage,oneside,final]{book}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[font=\footnotesize]
\tikzset{every node/.style=
   {align=center, minimum height=18pt, text width=80pt}}

\node[,draw=black] (b1) {Model-base};
\node[right=5pt,draw=black] (b2) at (b1.east) {Knowledge-base};
\node [below=5pt,draw=black] (c1) at (b1.south) {Physics-of-Failure};
\node [below=5pt,draw=black] (d1) at (c1.south) {Satistical Model};
\node [below=5pt] (dd1) at (d1.south) {\footnotesize Proportion Hazard};
\node [below=5pt] (dd2) at (dd1.south) {\footnotesize Logistics Regression};
  \node [below=5pt] (dd3) at (dd2.south) {\footnotesize Cumulative Damage};
  \node [below=5pt, draw=black] (e1) at (dd3.south) {\footnotesize Kalman/Particle Filtering};
\node[right=5pt,draw=black] (b3) at (b2.east) {Experience-base};  
\node[right=5pt,draw=black] (b4) at (b3.east) {Data-driven};
\node[above=10pt, text width=160pt,draw=black] (top) at ($(b2.north)!.5!(b3.north)$) {Life Prediction \\ Approaches and Techniques};
\coordinate (atop) at ($(top.south) + (0,-5pt)$);% midpoint below top
\coordinate (btop) at ($(b3.south) + (0,-5pt)$);% midoint below b3
\draw[thick] (top.south) -- (atop)
(b1.north) |- (atop) -| (b4.north)
(b2.north) |- (atop) -| (b3.north);

% Draw Connecting Lines

\draw[->] (b1.west)-- ++(-7pt,0) -- ++(0,-23pt) -- ++(7pt,0);



\end{tikzpicture}
\end{document}

Here is the diagram for my code enter image description here

9

This is not quite like the image you posted since that image appears to be an irregular structure in that the levels are not uniformly formatted. The far right end of the tree appears to break with the level structure and there does not appear to be any regularity or logic here to work with. (Or, if there is some, it isn't obvious from your question.) Of course, you can lay out the chart irregularly if you wish, but then you need to lay things out at least partly by hand.

This provides a regular tree structure using the forest package. When I originally posted this answer, the format required a somewhat involved configuration. These days, it is simple to achieve a similar result thanks to the edges library. In case you are stuck with older software and cannot update, the original version, with explanation, is included below. However, that code is less flexible, as well as more complex, so should be used only as a last resort if you truly have no other choice.

Current Forest (v. 2+ with the edges library)

% ateb: https://tex.stackexchange.com/a/271349/ addaswyd o gwestiwn OOzy Pal: https://tex.stackexchange.com/q/271170/
\documentclass[border=20pt,tikz]{standalone}
\usepackage[edges]{forest}

\forestset{
  direction switch/.style={
    for tree={edge+=thick, font=\sffamily},
    where level>=1{folder, grow'=0}{for children=forked edge},
    where level=3{}{draw},
  },
}
\begin{document}

\begin{forest}
  % forest preamble: determine layout and format of tree
  direction switch
  [Life Prediction Approaches and Techniques
    [Model-base
      [Physics-of-Failure
      ]
      [Satistical Model
        [Proportion Hazard Model]
        [Logistics Regression Model]
        [Cumulative Damage Model]
      ]
      [Kalman/Particle Filtering
      ]
      [Nonlinear Dynamics
      ]
    ]
    [Knowledge-base
      [Expert Systems
        [Rule-Based]
        [Model-Based]
        [Case-Based]
      ]
      [Fuzzy Logics
      ]
    ]
    [Experience-base
      [Parametric Distribution
        [Location Scale \& Log-Location Scale]
        [Normal \& Lognormal]
        [Smallest \& Largest Extreme Values]
        [Something Beginning with W]
        [Logistic \& Log-Logistic]
      ]
      [Nonparametric Distribution
      ]
    ]
    [Data-driven
      [Multivariate Statistical Method
        [Principal Component Analysis]
        [Something \& Something Else]
        [Another Thing]
        [A Final Thing Here]
      ]
      [Black-Box Methods
        [Decision Trees]
        [Multilayer Perceptions]
        [Neural Networks]
        [Radial Basis Functions]
        [Vector Quantification]
      ]
      [Signal Analysis
        [Auto-Something Here]
        [Fourier Transform]
        [Filters]
        [Tidal Functions]
      ]
      [Graphical Model
        [Bayesian Network]
        [Hidden Markov Networks]
      ]
      [Self-Organising Feature Maps
      ]
    ]
  ]
\end{forest}
\end{document}

current result with <code>edges</code> library

Original answer for older Forest (v. 1 without the edges library)

Using the stage keys provided by that package, it is possible to layout level 3 of the tree (the first level is level 0) in a way that avoids overlapping nodes. However, there may be a nicer way to do it as this is a bit hackish for my taste: it involves manual intervention to fine-tune and adjust the positions of the nodes at levels 1-3. Although this is semi-programmatic, the 0.6 was determined by trial-and-error rather than by forest which means it will need adjustment if the contents of the tree changes significantly. It also results in a less than ideally balanced tree in terms of spacing.

I know that the author of forest is preparing a new version. I'm not sure if that version might support a better solution. Although probably there is a better solution with the current version and I'm just not understanding it.

Anyway, for what it is worth, here is the result:

imperfect tree

Code:

\documentclass[border=20pt,tikz]{standalone}
\usepackage{forest}

\forestset{
  direction switch/.style={
    for tree={
      if level=3{}{draw},
      thick,
      edge={thick},
      if level=1{
        child anchor=north,
        edge path={
          \noexpand\path [\forestoption{edge}] (!u.parent anchor) -- ++(0,-.5em) -| (.child anchor)\forestoption{edge label};
        },
        s sep+=.5em,
        for descendants={
          child anchor=west,
          align=left,
          edge path={
            \noexpand\path [\forestoption{edge}] (!u.parent anchor) ++(1em,0) |- (.child anchor)\forestoption{edge label};
          },
          fit=band,
        },
        for tree={
          parent anchor=south west,
          anchor=mid west,
          grow'=0,
          font=\sffamily,
          if n children=0{}{
            delay={
              prepend={[,phantom, calign with current]}
            }
          },
          before computing xy={
            l=2em
          },
        },
        before drawing tree={
          x/.wrap pgfmath arg={##1}{.6*x()},
          for children={
            x/.wrap pgfmath arg={##1+1em}{.6*x()},
            for children={
              x/.wrap pgfmath arg={##1+2em}{.6*x()},
            }
          }
        }
      }{
        if level=0{
          parent anchor=south,
          anchor=south,
        }{},
      },
    },
  }
}
\begin{document}

\begin{forest}
  % forest preamble: determine layout and format of tree
  direction switch
  [Life Prediction Approaches and Techniques
    [Model-base
      [Physics-of-Failure
      ]
      [Satistical Model
        [Proportion Hazard Model]
        [Logistics Regression Model]
        [Cumulative Damage Model]
      ]
      [Kalman/Particle Filtering
      ]
      [Nonlinear Dynamics
      ]
    ]
    [Knowledge-base
      [Expert Systems
        [Rule-Based]
        [Model-Based]
        [Case-Based]
      ]
      [Fuzzy Logics
      ]
    ]
    [Experience-base
      [Parametric Distribution
        [Location Scale \& Log-Location Scale]
        [Normal \& Lognormal]
        [Smallest \& Largest Extreme Values]
        [Something Beginning with W]
        [Logistic \& Log-Logistic]
      ]
      [Nonparametric Distribution
      ]
    ]
    [Data-driven
      [Multivariate Statistical Method
        [Principal Component Analysis]
        [Something \& Something Else]
        [Another Thing]
        [A Final Thing Here]
      ]
      [Black-Box Methods
        [Decision Trees]
        [Multilayer Perceptions]
        [Neural Networks]
        [Radial Basis Functions]
        [Vector Quantification]
      ]
      [Signal Analysis
        [Auto-Something Here]
        [Fourier Transform]
        [Filters]
        [Tidal Functions]
      ]
      [Graphical Model
        [Bayesian Network]
        [Hidden Markov Networks]
      ]
      [Self-Organising Feature Maps
      ]
    ]
  ]
\end{forest}
\end{document}
  • I am getting a "! Dimension too large." error. I am using Kile in Ubuntu. Thx – OOzy Pal Oct 7 '15 at 5:38
  • Now, I tried it on Texstudio in Windows. I did not get the error but the graph was truncated from the right. I will try to make the font smaller and see. Thx – OOzy Pal Oct 7 '15 at 5:59
  • Hello, I fixed it using \resizebox{\linewidth}{!}{ code } – OOzy Pal Oct 7 '15 at 11:49
  • @OOzyPal That's odd. I'm using Kile on Arch/Fedora and don't get that problem. – cfr Oct 7 '15 at 15:28
  • @OOzyPal where to add \resizebox{\linewidth}{!}{ code }>? – Md Jalil Piran Jul 12 '18 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.