0

This question builds upon a previous question I posted here.

The following code:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta, shapes.geometric, calc, shadows}

\colorlet{mygreen}{green!75!black}
\colorlet{col1in}{red!30}
\colorlet{col1out}{red!40}
\colorlet{col2in}{mygreen!40}
\colorlet{col2out}{mygreen!50}
\colorlet{col3in}{blue!30}
\colorlet{col3out}{blue!40}
\colorlet{col4in}{mygreen!20}
\colorlet{col4out}{mygreen!30}
\colorlet{col5in}{blue!10}
\colorlet{col5out}{blue!20}
\colorlet{col6in}{blue!20}
\colorlet{col6out}{blue!30}
\colorlet{col7out}{orange}
\colorlet{col7in}{orange!50}
\colorlet{col8out}{orange!40}
\colorlet{col8in}{orange!20}
\colorlet{linecol}{blue!60}

\begin{document}
\pgfkeys{/forest,
  rect/.append style   = {rectangle, rounded corners = 2pt,
                         inner color = col6in, outer color = col6out},
  ellip/.append style  = {ellipse, inner color = col5in,
                          outer color = col5out},
  orect/.append style  = {rect, font = \sffamily\bfseries\LARGE,
                         text width = 325pt, text centered,
                         minimum height = 10pt, outer color = col7out,
                         inner color=col7in},
  oellip/.append style = {ellip, inner color = col8in, outer color = col8out,
                          font = \sffamily\bfseries\large, text centered}}
\begin{forest}
  for tree={
      font=\sffamily\bfseries,
      line width=1pt,
      draw=linecol,
      ellip,
      align=center,
      child anchor=north,
      parent anchor=south,
      drop shadow,
      l sep'+=12.5pt,
      edge+={color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->},
      edge path'={(!u.parent anchor) -- +(0,-5pt) -| (.child anchor)},
  }
  [Start, inner color=col1in, outer color=col1out,name=rootNode
    [X1, inner color=col2in, outer color=col2out, name=X1
          [A longer string, rect, name=Y1
            [Short, rect, name=Z1
            ]
            [Short, rect, name=Z2
            ]
            [Short, rect, name=Z3
            ]
            [Short, rect, name=Z4
            ]
            [Short, rect, name=Z5
            ]
            [Short, rect, name=Z6
            ]
            [Short, rect, name=Z7
            ]
            [Short, rect, name=Z8
            ]
          ]
          [A longer string, rect, name=Y2
          ]
          [A longer string, rect, name=Y3
          ]
          [A longer string, rect, name=Y4
          ]
          [A longer string, rect, name=Y5
          ]
          [A longer string, rect, name=Y6
          ]
          [A longer string, rect, name=Y7
          ]
          [A longer string, rect, name=Y8
          ]
    ]
    [X2, inner color=col3in, outer color=col3out,name=X2
    ]
  ]
  \begin{scope}[color = linecol, rounded corners = 5pt, >={Stealth[length=10pt]}, line width=1pt, ->]
    \draw (X2.parent anchor) -- +(0,-5pt) -| (Y1.child anchor);
    \draw (Y1.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
    \draw (Y2.parent anchor) -- +(0,-5pt) -| (Z2.child anchor);
    \draw (Y3.parent anchor) -- +(0,-5pt) -| (Z3.child anchor);
    \draw (Y4.parent anchor) -- +(0,-5pt) -| (Z4.child anchor);
    \draw (Y5.parent anchor) -- +(5pt,-5pt) -| (Z1.child anchor);
    \draw (Y6.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
    \draw (Y7.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
    \draw (Y8.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
  \end{scope}
\end{forest}
\end{document}

produces this output:

Output image.

However, this is very left-centered. I would like to have a centered output, such that every row of the output diagram aligns with the parent row. Help is very much appreciated.

2
  • 1
    did you want something like the answer below – js bibra Jan 23 at 6:56
  • Yes, indeed. Thank you very much! :-) – Hagbard Jan 23 at 21:12
1

enter image description here

\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta, shapes.geometric, calc, shadows}

\colorlet{mygreen}{green!75!black}
\colorlet{col1in}{red!30}
\colorlet{col1out}{red!40}
\colorlet{col2in}{mygreen!40}
\colorlet{col2out}{mygreen!50}
\colorlet{col3in}{blue!30}
\colorlet{col3out}{blue!40}
\colorlet{col4in}{mygreen!20}
\colorlet{col4out}{mygreen!30}
\colorlet{col5in}{blue!10}
\colorlet{col5out}{blue!20}
\colorlet{col6in}{blue!20}
\colorlet{col6out}{blue!30}
\colorlet{col7out}{orange}
\colorlet{col7in}{orange!50}
\colorlet{col8out}{orange!40}
\colorlet{col8in}{orange!20}
\colorlet{linecol}{blue!60}

\begin{document}
\pgfkeys{/forest,
  rect/.append style   = {rectangle, rounded corners = 2pt,
                         inner color = col6in, outer color = col6out},
  ellip/.append style  = {ellipse, inner color = col5in,
                          outer color = col5out},
  orect/.append style  = {rect, font = \sffamily\bfseries\LARGE,
                         text width = 325pt, text centered,
                         minimum height = 10pt, outer color = col7out,
                         inner color=col7in},
  oellip/.append style = {ellip, inner color = col8in, outer color = col8out,
                          font = \sffamily\bfseries\large, text centered}}
\begin{forest}
  for tree={
      font=\sffamily\bfseries,
      line width=1pt,
      draw=linecol,
      ellip,
      align=center,
      child anchor=north,
      parent anchor=south,
      drop shadow,
      l sep'+=12.5pt,
      edge+={color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->},
      edge path'={(!u.parent anchor) -- +(0,-5pt) -| (.child anchor)},
  }
  [Start, inner color=col1in, outer color=col1out,name=rootNode
    [X1, inner color=col2in, outer color=col2out, name=X1
          [A longer string, rect, name=Y1
          ]
          [A longer string, rect, name=Y2
          ]
          [A longer string, rect, name=Y3
          ]
          [A longer string, rect, name=Y4
          [Short, rect, name=Z1
          ]
          [Short, rect, name=Z2
          ]
          [Short, rect, name=Z3
          ]
          [Short, rect, name=Z4
          ]
          [Short, rect, name=Z5
          ]
          [Short, rect, name=Z6
          ]
          [Short, rect, name=Z7
          ]
          [Short, rect, name=Z8
          ]]
          [A longer string, rect, name=Y5
          ]
          [A longer string, rect, name=Y6
          ]
          [A longer string, rect, name=Y7
          ]
          [A longer string, rect, name=Y8
          ]
    ]
    [X2, inner color=col3in, outer color=col3out,name=X2
    ]
  ]
  \begin{scope}[color = linecol, rounded corners = 5pt, >={Stealth[length=10pt]}, line width=1pt, ->]
    \draw (X2.parent anchor) -- +(0,-5pt) -| (Y1.child anchor);
    \draw (Y1.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
    \draw (Y2.parent anchor) -- +(0,-5pt) -| (Z2.child anchor);
    \draw (Y3.parent anchor) -- +(0,-5pt) -| (Z3.child anchor);
    \draw (Y4.parent anchor) -- +(0,-5pt) -| (Z4.child anchor);
    \draw (Y5.parent anchor) -- +(5pt,-5pt) -| (Z1.child anchor);
    \draw (Y6.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
    \draw (Y7.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
    \draw (Y8.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
  \end{scope}
\end{forest}
\end{document}

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.