2

I am looking for an extension of the existing question and discussion enter image description here

\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\begin{document}
\colorlet{myyellow}{yellow!50}
\begin{forest}
colour me/.style={top color=#1!75, bottom color=#1, draw=#1, thick, blur shadow, rounded corners},
for tree={
edge=-Latex,
font=\sffamily,
},
where level=1{
for tree={
  folder,
  grow'=0,
},
edge path'={(!u.parent anchor) -- ++(0,-15pt) -| (.child anchor)},
}{},
before typesetting nodes={for tree={content/.wrap value={\strut #1},},
if={isodd(n_children("!r"))}{
  for nodewalk/.wrap pgfmath arg={{fake=r,n=#1}{calign with current edge}}{int((n_children("!r")+1)/2)},
}{},
tempcounta/.max={level}{tree},
for tree={
  colour me/.wrap pgfmath arg={cyan!#1!myyellow}{100*((tempcounta)-level())/(tempcounta)}
}
}
[Project Plan
[Objective-A
  [A1]
  [A2]
  [A3]
  [A4]
]
[Objective-B
  [B1]
  [B2]
  [B3]
  [B4[Extra]]
 [ \hspace{0.0cm} Data Analysis, no edge, colour me=red]
]
[Objective-C
  [C1]
  [C2]
  [C3]
  [C4]
  [C5]
]
[Objective-D
  [D1]
  [D2]
  [D3]
  [D4]
]
]
\end{forest}
\end{document}
Nachi
  • 21
  • Welcome! Please note that if you use code from elsewhere, it should be attributed to its author and you should provide a link. – cfr Sep 08 '17 at 13:13
  • @cfr Thanks for the suggestion, please find the reference. – Nachi Sep 09 '17 at 02:25

1 Answers1

4

You can't add these to the tree specification, as they make it a non-tree, but you can use regular TikZ to add them, optionally via the tikz key.

\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\begin{document}
\colorlet{myyellow}{yellow!50}
\begin{forest}
  colour me/.style={top color=#1!75, bottom color=#1, draw=#1, thick, blur shadow, rounded corners},
  for tree={edge=-Latex, font=\sffamily,},
  where level=1{
    for tree={folder, grow'=0, },
    edge path'={(!u.parent anchor) -- ++(0,-15pt) -| (.child anchor)},
    if nodewalk valid={p}{tikz+={\draw [-Latex] (!p) -- (); } }{},
  }{},
  before typesetting nodes={for tree={content/.wrap value={\strut #1},},
    if={isodd(n_children("!r"))}{
      for nodewalk/.wrap pgfmath arg={{fake=r,n=#1}{calign with current edge}}{int((n_children("!r")+1)/2)},
    }{},
    tempcounta/.max={level}{tree},
    for tree={
      colour me/.wrap pgfmath arg={cyan!#1!myyellow}{100*((tempcounta)-level())/(tempcounta)}
    },
  },
  [Project Plan
  [Objective-A, tikz+={\draw [-Latex] (.west) -- ++(-5pt,0) |- (da.west);  }
    [A1]
    [A2]
    [A3]
    [A4]
  ]
  [Objective-B
    [B1]
    [B2]
    [B3]
    [B4[Extra]]
   [Data Analysis, no edge, colour me=red, name=da]
  ]
  [Objective-C
    [C1]
    [C2]
    [C3]
    [C4]
    [C5]
  ]
  [Objective-D, tikz+={\draw [-Latex] (.east) -- ++(5pt,0) |- (da.east);  }
    [D1]
    [D2]
    [D3]
    [D4]
  ]
]
\end{forest}
\end{document}

added arrows

EDIT

If you want the root to be more centralised, you might centre it either between the first and last child or between the second and third. This code takes the former option, but could be easily adapted to implement the latter.

\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\begin{document}
\colorlet{myyellow}{yellow!50}
\begin{forest}
  colour me/.style={top color=#1!75, bottom color=#1, draw=#1, thick, blur shadow, rounded corners},
  for tree={edge=-Latex, font=\sffamily,},
  where level=1{
    for tree={folder, grow'=0, },
    edge path'={(!u.parent anchor) -- ++(0,-15pt) -| (.child anchor)},
    if nodewalk valid={p}{tikz+={\draw [-Latex] (!p) -- (); } }{},
  }{},
  before typesetting nodes={
    for tree={content/.wrap value={\strut #1},},
    if={isodd(n_children("!r"))}{
      for nodewalk/.process={Ow+nw{!r.n children}{(#1+1)/2}{fake=r,n=#1}{calign with current edge}},
    }{},
    tempcounta/.max={level}{tree},
    for tree={
      colour me/.process={ROw2+Pw{tempcounta}{level}{100*(#1-#2)/#1}{cyan!#1!myyellow}},
    },
  },
  before drawing tree={%
    tempdima'=0pt,
    for nodewalk={
      fake=r, 1, tempdima/.option=x, tempdima+/.option=min x, fake=r, l, tempdima+/.option=x, tempdima+/.option=max x
    }{},
    tempdima*=.5,
    x/.register=tempdima,   
  }
  [Project Plan, 
  [Objective-A, tikz+={\draw [-Latex] (.west) -- ++(-5pt,0) |- (da.west);  }
    [A1]
    [A2]
    [A3]
    [A4]
  ]
  [Objective-B
    [B1]
    [B2]
    [B3]
    [B4[Extra]]
   [Data Analysis, no edge, colour me=red, name=da]
  ]
  [Objective-C
    [C1]
    [C2]
    [C3]
    [C4]
    [C5]
  ]
  [Objective-D, tikz+={\draw [-Latex] (.east) -- ++(5pt,0) |- (da.east);  }
    [D1]
    [D2]
    [D3]
    [D4]
  ]
]
\end{forest}
\end{document}

more centralised root

cfr
  • 198,882
  • is possible to horizontal center "project plan" in relative to "objective b" and "objective c"? (+1 for nice answer) – Zarko Sep 09 '17 at 02:32
  • @Zarko You could. Easier would be to align with the midpoint between the primary and secondary child. Right now, the code really is designed for a root with an odd number of children. However, the switch to directory-style always screws things up because it doesn't really expect changes of style of this kind. – cfr Sep 09 '17 at 02:36
  • @Zarko Please see edit above. You can change it to the second/third child if you want, but I used the first/last in my example (partly because it is a bit more obvious that way). – cfr Sep 09 '17 at 23:15
  • @cfr, amazing! ow already understand most of your code, but important part still make me (huge) problems. thank you that you take my comment into consideration. – Zarko Sep 09 '17 at 23:33
  • There's redundant code in there now. The mid point stuff should be in the else bit of the conditional ... @Zarko – cfr Sep 09 '17 at 23:46