
私はtree layout
tikz を使用していますが、これは通常は非常にうまく機能しますが、サブグラフを使用すると、次のようにエッジが互いに完全に重なり合うことがあります。
以下のコードでは、 や電気バリアントなど、さまざまな他のレイアウト方法も試しましたspring layout
。しかし、それらもネストされたレイアウトで同様に問題があるようで、力がレベルを通じてうまく伝わりません。その結果、多数のノードが互いに重なり合うことになります。
ネストされたレイアウトでレイアウトを取得するために必要なトリックはありますか?
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs, graphdrawing, quotes, arrows.meta}
\usegdlibrary{trees}
\begin{document}
\tikz[
every node/.style={
font=\scriptsize,
inner sep=2pt,
},
identity/.style={circle, draw=black, fill=white, inner sep=0pt, minimum size=4pt},
var/.style={circle, draw=black, fill=white, inner sep=2pt},
function/.style={circle, draw=black, fill=white, inner sep=2pt},
subgraph nodes={draw=gray, rounded corners},
subgraph text none,
]
\graph [
tree layout,
grow'=right,
fresh nodes,
sibling sep=5em,
node distance=1cm,
node sep=1cm,
nodes behind edges,
nodes={align=center},
] {
main+cluster [draw=black, circle] // [tree layout]{
sub+cluster // [tree layout]{
node+A[function,as=$A$];
node+x1[var,as=$x$];
(node+x1) -> [-latex, "$i$"] (node+A);
},
node+x2[var,as=$x$];
(node+A) -- ["$i$"] (node+x2);
},
node+j[as=];
(node+A) -- ["$j$"] (node+j);
node+i+prime[as=];
(main+cluster) -- [Circle-, "$i'$"] (node+i+prime);
};
\end{document}
答え1
ここに提案があります。 を使用してx
ノードを下に移動しnudge down =5mm
、 を使用して矢印を曲げましたout=-80,in=230,looseness=1.4
。 これらの設定を変更して、これを自分のアイデアにできるだけ近づけることができます。
node+x2[var,nudge down=5mm,as=$x$];
(node+A) -- [out=-80,in=230,looseness=1.4,"$i$"] (node+x2);
完全なコード
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs, graphdrawing, quotes, arrows.meta}
\usegdlibrary{trees}
\begin{document}
\tikz[
every node/.style={
font=\scriptsize,
inner sep=2pt,
},
identity/.style={circle, draw=black, fill=white, inner sep=0pt, minimum size=4pt},
var/.style={circle, draw=black, fill=white, inner sep=2pt},
function/.style={circle, draw=black, fill=white, inner sep=2pt},
subgraph nodes={draw=gray, rounded corners},
subgraph text none,
]
\graph [
tree layout,
grow'=right,
fresh nodes,
sibling sep=5em,
node distance=1cm,
node sep=1cm,
nodes behind edges,
nodes={align=center},
] {
main+cluster [draw=black, circle] // [tree layout]{
sub+cluster // [tree layout]{
node+A[function,as=$A$];
node+x1[var,as=$x$];
(node+x1) -> [-latex, "$i$"] (node+A);
},
node+x2[var,nudge down=5mm,as=$x$];
(node+A) -- [out=-80,in=230,looseness=1.4,"$i$"] (node+x2);
},
node+j[as=];
(node+A) -- ["$j$"] (node+j);
node+i+prime[as=];
(main+cluster) -- [Circle-, "$i'$"] (node+i+prime);
};
\end{document}