
パッケージに関して質問があります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 を押すと、すべてを直接配置できます。
ツリーの構造を変更する準備ができている場合 (自動的に変更することもできますが、このパターンだけで非常に多くのツリーがある場合を除いて、私は気にしません)、座標ノードを使用して成長の方向を変更できます。つまり、一部の子は現在の親の孫になり、座標が親になります。次に、別の 3 つの座標セットを挿入して、元の子を元の親のひ孫にする必要があります。コードがさらに複雑になる価値があるとは思いませんが、例を示します。
\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
? ここではそのままにしていますが、奇妙なアイデアだと思います。