Cambie y mezcle el estilo de carpeta en el paquete forestal al crear árboles

Cambie y mezcle el estilo de carpeta en el paquete forestal al crear árboles

Tengo una pregunta sobre el forestpaquete. Me gustaría cambiar el siguiente árbol para ahorrar algo de espacio vertical cambiando el estilo de la carpeta en un cierto nivel para que se alterne o crezca en una dirección diferente. Ante eso, no sé por qué el primer nivel no está alineado verticalmente.

Pregunta adicional: ¿Cómo es posible tener una estructura de carpetas alternada? Como

            A
            |-B
          C-|
or even   E-|-D

Lo que me gustaría tener es algo como esto.

Salida deseada

Aquí está mi MWE:

\documentclass[tikz,multi]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows}

\begin{document}
    \begin{forest}
      basic/.style = {draw, thin, drop shadow, font=\sffamily},
      my root/.style = {basic, rounded corners=2pt, fill=black!2},
      upper style/.style = {basic, rounded corners=6pt, fill=black!6, text width=10.5em},
      lower style/.style = {basic, rounded corners=0pt,fill=black!10, text width=9em},
      for tree={%
        parent anchor=south,
        child anchor=north,
        edge path={
          \noexpand\path [-{Stealth[]}, \forestoption{edge}, thin]
            (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)\forestoption{edge label};
        },
        /tikz/>=LaTeX,
      },
      where level=0{%
        my root,
        %for 1={%
          for tree={%
            if={level()<3}{%
              upper style,
            }{%
              lower style,
            },
            if={level()<2}{%
              if={isodd(n_children())}{%
                calign=child edge,
                calign primary child/.wrap pgfmath arg={#1}{int((n_children()+1)/2)},
              }{%
                calign=edge midpoint,
              },
            }{%
              folder,
              grow'=0,
            },
          },
      }{},
      [Alphabet
        [First five letters, folder, grow'=0,
          [A, lower style,]
          [B, lower style,]
          [C, lower style,]
          [D, lower style,]
          [E, lower style, text width=12em]
        ]
        [Some header]
        [More letters
          [Two
            [F]
            [G]
          ]
          [Nine
            [H]
            [I]
            [J]
            [K]
            [L]
            [M]
            [N]
            [O]
            [And a longer box, text width=12em]
          ]
          [Some more stuff
            [to fill]
            [this tree]
          ]
        ]
      ]
    \end{forest}
\end{document}

¡Gracias por tu tiempo!

Respuesta1

El folderestilo no está realmente diseñado teniendo en mente cambios de dirección de crecimiento, no lo creo. Por lo tanto, requiere algunos ajustes manuales después del hecho. Al menos, creo que la forma más sencilla es mover el subárbol relevante antes de dibujar el árbol.

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows}
\begin{document}
\begin{forest}
  basic/.style = {draw, thin, drop shadow, font=\sffamily},
  upper style/.style = {basic, rounded corners=6pt, edge+={-Stealth, thin}, fill=black!6, text width=10.5em},
  lower style/.style = {basic, rounded corners=0pt, edge+={-, line width=.4pt}, fill=black!10, text width=9em},
  where level<=2{%
    upper style,
    edge path'={
      (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)
    },
  }{%
    lower style,
  },
  where level<=1{%
    parent anchor=children,
    child anchor=parent,
    if={isodd(n_children())}{%
      calign=child edge,
      calign primary child/.process={
        O+nw+n{n children}{(#1+1)/2}
      },
    }{%
      calign=edge midpoint,
    },
  }{
    folder,
    grow'=0,
  },
  [Alphabet
    [First five letters, folder, grow'=0, for children={lower style},
      before drawing tree={
        tempdima/.option=!r2.max y,
        tempdima-/.option=max y,
        for tree={
          y+/.register=tempdima,
        },
      }
      [A]
      [B]
      [C]
      [D]
      [E, text width=12em]
    ]
    [Some header]
    [More letters
      [Two
        [F]
        [G]
      ]
      [Nine
        [H]
        [I]
        [J]
        [K]
        [L]
        [M]
        [N]
        [O]
        [And a longer box, text width=12em]
      ]
      [Some more stuff
        [to fill]
        [this tree]
      ]
    ]
  ]
\end{forest}
\end{document}

primer nivel alineado

Creo que los deseos adicionales no son posibles con Forest sin cambiar la estructura del árbol. Es decir, puedes fingir, pero no puedes poner a algunos niños de una manera y otros de otra, sin mover manualmente un conjunto u otro, en cuyo punto, probablemente sea más fácil abandonar Forest y usar Ti.kZ para colocar todo directamente.

Si está preparado para cambiar la estructura del árbol (lo que incluso podría hacer automáticamente, aunque no me molestaría a menos que tenga muchos con solo este patrón), podría usar un nodo de coordenadas para cambiar la dirección de crecimiento, es decir, algunos de los hijos se convertirían en nietos de su padre actual y usted tendría una coordenada como su padre. Luego necesitaría insertar otro conjunto de tres coordenadas, convirtiendo a los hijos originales en bisnietos de su padre original. Dudo que valga la pena la complejidad adicional del código, pero aquí hay un ejemplo.

\begin{forest}
  basic/.style = {draw, thin, drop shadow, font=\sffamily},
  upper style/.style = {basic, rounded corners=6pt, edge+={-Stealth, thin}, fill=black!6, text width=10.5em},
  lower style/.style = {basic, rounded corners=0pt, edge+={-, line width=.4pt}, fill=black!10, text width=9em},
  where level<=2{%
    upper style,
    edge path'={
      (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)
    },
  }{%
    lower style,
  },
  where level<=1{%
    parent anchor=children,
    child anchor=parent,
    if={isodd(n_children())}{%
      calign=child edge,
      calign primary child/.process={
        O+nw+n{n children}{(#1+1)/2}
      },
    }{%
      calign=edge midpoint,
    },
  }{
    folder,
    grow'=0,
  },
  [Alphabet
    [First five letters, folder, grow'=0, for children={lower style},
      before drawing tree={
        tempdima/.option=!r2.max y,
        tempdima-/.option=max y,
        for tree={
          y+/.register=tempdima,
        },
      }
      [A]
      [B]
      [C]
      [D]
      [E, text width=12em]
    ]
    [Some header]
    [More letters
      [Two
        [F]
        [G]
      ]
      [Nine
        [H]
        [I]
        [J]
        [K]
        [, coordinate, grow'=-90, for descendants={edge path'={(!u.parent anchor) |- (.child anchor)}}, before packing={calign primary child=2}
          [, coordinate
            [And a longer box, text width=12em]
          ]
          [, coordinate
            [N]
            [O]
          ]
          [, coordinate
            [L]
            [M]
          ]
        ]
      ]
      [Some more stuff
        [to fill]
        [this tree]
      ]
    ]
  ]
\end{forest}

árbol reestructurado

Por cierto, ¿por qué quieres que algunos bordes tengan un ancho regular y otros thin? Aunque lo he conservado aquí, creo que es una idea extraña.

información relacionada