私は、図のような木を描きたいです。このスレッドただし、ノード内のテキストが長すぎて改行が必要になる場合があります。次に、anchor=150
スレッドのオプションによってgrandchildren
ノードの水平方向の配置が台無しになります。anchor=west
水平方向の配置を使用すると、ノードが右にずれて次の列と交差します。
それを避けるにはどうしたらいいでしょうか?
ムウェ
\documentclass{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
% \usetikzlibrary{fpu}
\usetikzlibrary{intersections}
\usetikzlibrary{trees}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\useforestlibrary{edges}
\tikzset{
parent/.style={align=center,text width=4cm,fill=gray!50,rounded corners=2pt},
child/.style={align=center,text width=2.5cm,fill=gray!20,rounded corners=6pt},
grandchild/.style={fill=white,text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
thick,
drop shadow,
l sep=0.8cm,
s sep=1.0cm,
node options={
draw,
font=\sffamily
},
edge={
semithick,
-Latex
},
where level=0{parent}{},
where level=1{
minimum height=1cm,
child,
parent anchor=south west,
tier=p,
l sep=0.45cm,
for descendants={%
grandchild,
minimum height=0.6cm,
anchor=west,
edge path={
\noexpand\path[\forestoption{edge}]
(!to tier=p.parent anchor) |-(.child anchor)\forestoption{edge label};
},
}
}{},
}
[\large Long text with line break%
[\textbf{Test 1} \\ with a lot of subtext%
[Topic%
[Long topic with line break%
[Topic%
]]]%
]
[\textbf{Test 2} \\ with a lot of subtext%
[Topic%
[Long topic with line break%
[Topic%
]]]%
]
[\textbf{Test 3} \\ with a lot of subtext%
[Topic%
[Long topic with line break%
[Topic%
]]]%
]
[\textbf{Test 4} \\ with a lot of subtext%
[Topic%
[Long topic with line break%
[Topic%
]]]%
]
]
\end{forest}
\end{document}
結果
答え1
ライブラリをロードしていますedges
が、実際には使用していません。これは、ライブラリがサポートするスタイルの種類とまったく同じなので、奇妙なことです。さらに、ツリーの構造を偽装する必要がなくなり、マークアップ内で直感的な親子関係を維持できます。
この場合、folder
誤解を招く名前を無視すれば、スタイルは明らかな選択です。唯一の問題は、特定のレベルを超えてのみ適用される場合は正しく動作しないことと、賢い方法で正しい動作をしようとするため、ツリーの処理の後半でスタイルをオーバーライドする必要があることです。
例えば、
\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{shadows,arrows.meta}
\tikzset{
parent/.style={align=center,text width=4cm,fill=gray!50,rounded corners=2pt},
child/.style={align=center,text width=2.5cm,fill=gray!20,rounded corners=6pt},
grandchild/.style={fill=white,text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
thick,
drop shadow,
node options={
draw,
font=\sffamily
},
edge={
semithick,
-Latex
},
where level=0{
parent,
l sep'=0.8cm,
s sep'=1.0cm,
}{
folder,
grow'=0,
},
where level=1{
minimum height=1cm,
child,
l sep=7.5mm,
for descendants={%
grandchild,
minimum height=0.6cm,
},
for children={
before computing xy={s+=5mm},
}
}{},
}
[\large Long text with line break%
[\textbf{Test 1} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
[\textbf{Test 2} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
[\textbf{Test 3} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
[\textbf{Test 4} \\ with a lot of subtext%
[Topic]
[Long topic with line break]
[Topic]
]
]
\end{forest}
\end{document}