
Tenho uma dúvida em relação ao forest
pacote. Gostaria de alterar a árvore a seguir para economizar espaço vertical, alterando o estilo da pasta em um determinado nível para alternar ou crescer em uma direção diferente. Para isso, não sei porque o primeiro nível não está alinhado verticalmente.
Pergunta bônus: Como é possível ter uma estrutura de pastas alternada? Como
A
|-B
C-|
or even E-|-D
O que eu gostaria de ter é algo assim.
Aqui está meu 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}
Obrigado pelo seu tempo!
Responder1
O folder
estilo não foi realmente projetado com mudanças na direção do crescimento em mente, eu não acho. Portanto, requer alguns ajustes manuais após o fato. Pelo menos, acho que a maneira mais fácil é mover a subárvore relevante antes que a árvore seja desenhada.
\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}
Penso que outros desejos não são possíveis com Forest sem alterar a estrutura da árvore. Ou seja, você poderia fingir, mas não pode colocar alguns filhos de um jeito e outros de outro, sem mover manualmente um conjunto ou outro, e nesse ponto provavelmente será mais fácil abandonar Forest e usar TikZ para colocar tudo diretamente.
Se você estiver preparado para alterar a estrutura da árvore (o que você pode até fazer automaticamente, embora eu não me incomodaria, a menos que você tenha muitos com apenas esse padrão), você poderia usar um nó de coordenadas para alterar a direção do crescimento, ou seja, alguns dos filhos se tornariam netos de seus pais atuais e você teria uma coordenada como pai. Você precisaria então inserir outro conjunto de três coordenadas, tornando os filhos originais bisnetos de seus pais originais. Duvido que valha a pena a complexidade adicional do código, mas aqui está um exemplo.
\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}
A propósito, por que você quer que algumas arestas tenham largura regular e outras thin
? Embora eu tenha preservado aqui, acho uma ideia estranha.