나무를 만들 때 포레스트 패키지에서 폴더 스타일을 변경하고 혼합합니다.

나무를 만들 때 포레스트 패키지에서 폴더 스타일을 변경하고 혼합합니다.

패키지 관련 질문이 있습니다 forest. 특정 수준의 폴더 스타일을 다른 방향으로 번갈아 가거나 자라도록 변경하여 수직 공간을 절약하기 위해 다음 트리를 변경하고 싶습니다. 그런데 왜 첫 번째 레벨이 수직으로 정렬되어 있지 않은지 모르겠습니다.

보너스 질문: 대체 폴더 구조를 갖는 것이 어떻게 가능합니까? 와 같은

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

내가 갖고 싶은 것은 이런 것이다.

원하는 출력

내 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}

시간 내 줘서 고마워!

답변1

스타일 folder은 실제로 성장 방향의 변화를 염두에 두고 디자인된 것이 아니라고 생각합니다. 따라서 사후에 일부 수동 조정이 필요합니다. 적어도 가장 쉬운 방법은 트리가 그려지기 전에 해당 하위 트리를 이동하는 것이라고 생각합니다.

\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}

정렬된 첫 번째 수준

내 생각에는 트리의 구조를 바꾸지 않고서는 Forest를 사용하는 것이 더 이상 바람직하지 않습니다. 즉, 가짜로 만들 수는 있지만 수동으로 한 세트 또는 다른 세트를 이동하지 않고는 일부 어린이를 이쪽 저쪽으로 배치할 수 없습니다. 이 시점에서는 Forest를 버리고 Ti를 사용하는 것이 더 쉬울 것입니다.케이Z는 모든 것을 직접 배치합니다.

트리의 구조를 변경할 준비가 되었다면(자동으로 수행할 수도 있지만 이 패턴만으로 너무 많은 것이 아니라면 귀찮게 하지 않겠습니다) 좌표 노드를 사용하여 성장 방향을 변경할 수 있습니다. 자녀 중 현재 부모의 손자가 되며 여러분은 그들의 부모로서 좌표를 갖게 됩니다. 그런 다음 다른 세 개의 좌표 세트를 삽입하여 원래 자식을 원래 부모의 증손자로 만들어야 합니다. 코드를 더 복잡하게 만드는 것이 가치가 있는지 의심스럽습니다. 그러나 여기에 예가 있습니다.

\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}

재구성된 트리

그런데 왜 일부 가장자리를 일반 너비로 만들고 일부 가장자리를 로 설정하려고 합니까 thin? 여기에 보관해두긴 했지만 이상한 생각인 것 같아요.

관련 정보