Forest: How to horizontally center the parents nodes between their children?

Note that you did not ask how to do anything. You asked for an explanation of the alignment. Sašo's answer addressed that question.

I take it from your comment that what you meant to ask in your question body was what you actually ask in the subject line i.e. how to avoid the effect described in your question.

It would probably be simpler at this point to start over. However, hacking on Alan Munn's hacking on my code, you could do the following.

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\begin{document}
\newlength\gap
\setlength\gap{10mm}
\forestset{parent color/.style args={#1}{
    {fill=#1},
    for tree={fill/.wrap pgfmath arg={#1!##1}{1/level()*80},draw=#1!80!darkgray}},
    root color/.style args={#1}{fill={{#1!60!gray!25},draw=#1!80!darkgray}}
}
\begin{forest}
  forked edges,
  for tree={%
    rounded corners,
    minimum width=(\textwidth-6*\gap)/3,
    minimum height=4ex,
    edge={-Latex},
    font=\sffamily,
    text centered,
    blur shadow,
    parent anchor=children,
    child anchor=parent,
  },
  where={level()<=1}{%
    l sep+=10pt,
    s sep'+=10pt,
   }{%
     folder,
     grow'=0,
     l sep+=2pt,% length of edge to grand child - NO IT IS NOT!!!
     if level=2{%
       !u.s sep'+=10pt,
       anchor=north,
       child anchor=north,
       edge path'={%
         (!u.parent anchor) -- (.child anchor)
       },
     }{
       if level=3{
         before computing xy={l=14pt-((\textwidth-6*\gap)/6)},
       }{}
     },
   },
      [Grandparent,root color={brown}
        [Parent 1, parent color={red}
            [Child 1
                [Grandchild 1]
            ]
        ]
        [Parent 2,parent color={green}
            [Child 2
                [Grandchild 2]
            ]
        ]
        [Parent 3,parent color={yellow}
            [Child 3
                [Grandchild 3 [Great-Grandchild]]
            ]
        ]
    ]
\end{forest}
\end{document}

centred children at level 2

Alternatively, adapting my version of the code from family tree and branch shade to create family tree too and branch shading, we might write the following.

\documentclass[border=10pt,multi,tikz,dvipsnames,svgnames,rgb]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\forestset{
  declare dimen register=gap,
  gap'=10mm,
  declare count register=twist,
  twist'=2,
  family tree too/.style={
    forked edges,
    for tree={
      rounded corners,
      minimum width/.wrap pgfmath arg={##1}{(\textwidth-6*(gap))/3},
      minimum height=4ex,
      edge={-Latex},
      font=\sffamily,
      text centered,
      blur shadow,
      edge=thick,
    },
    where={level()<(twist)}{%
      parent anchor=children,
      l sep+=5pt,
    }{%
      folder,
      grow'=0,
      if={level()==(twist)}{%
        before typesetting nodes={child anchor=north},
        anchor=north,
        edge path'={%
          (!u.parent anchor) -- (.child anchor)
        },
      }{
        l sep'+=2pt,
        if level=3{
          before computing xy={
            l/.wrap pgfmath arg={##1}{14pt-((\textwidth-6*(gap))/6)}
          },
        }{}
      },
    },
  },
  branch shading/.style args={from #1 to #2}{
    before typesetting nodes={
      tempcountc/.max={level}{current,tree},
      tempcountb/.option=level,
      tempcounta=(tempcountc)-(tempcountb)+1,
      temptoksa/.option=name,
      TeX/.wrap pgfmath arg={
        \colorlet{##1col1}{#1}
        \colorlet{##1col2}{#2}
      }{name()},
      for tree={
        rounded corners,
        top color/.wrap 2 pgfmath args={##2col2!##1!##2col1}{100*((level()-(tempcountb))/(tempcounta))}{(temptoksa)},
        bottom color/.wrap 2 pgfmath args={##2col2!##1!##2col1}{100*((level()-(tempcountb)+1)/(tempcounta))}{(temptoksa)},
        draw/.wrap 2 pgfmath args={##2col2!##1!##2col1}{100*((level()-(tempcountb)+1)/(tempcounta))}{(temptoksa)},
        thick,
      },
      +edge=darkgray,
      for descendants={
        +edge/.wrap 2 pgfmath args={##2col2!##1!##2col1}{100*((level()-(tempcountb))/(tempcounta))}{(temptoksa)},
      },
    }
  },
}
\begin{document}
\begin{forest}
  family tree too,
   [Grandparent, left color=cyan, right color=SpringGreen, middle color=Pink, draw=Silver
     [Parent 1, branch shading=from cyan to blue
       [Child 1
         [Grandchild 1]
       ]
     ]
     [Parent 2, branch shading=from Pink to WildStrawberry
       [Child 2
         [Grandchild 2]
       ]
     ]
     [Parent 3, branch shading=from SpringGreen to ForestGreen
       [Child 3
         [Grandchild 3]
       ]
     ]
   ]
\end{forest}
\begin{forest}
  family tree too,
   [Grandparent, fill=darkgray, text=Silver, double=Silver, draw=darkgray
     [Parent 1, branch shading=from blue!80 to blue!20
       [Child 1
         [Grandchild 1]
       ]
     ]
     [Parent 2, branch shading=from WildStrawberry!80 to WildStrawberry!20
       [Child 2
         [Grandchild 2]
       ]
     ]
     [Parent 3, branch shading=from ForestGreen!80 to ForestGreen!20
       [Child 3
         [Grandchild 3]
       ]
     ]
   ]
\end{forest}
\end{document}

other possibilities


Style folder sets calign, among other things.

Also note that at a folder node, the tree actually grows to the east!

Tags:

Forest