
答え1
これは、このタイプのツリーをフォーマットするためのフォレストスタイルを定義するバージョンですstate tree
。例に基づく仮定は次のとおりです。
- 子どもたちは均等に分散されるべきである。
- 最初の子と最後の子は親から等距離にある必要があります。
- エッジは最初と最後の子に対してのみ描画する必要があります。
- ノードの内容は数式モードで入力する必要があります。
これらの仮定の 1 つ以上を修正する必要がある場合は、スタイルを変更することができます。
これはツリーのコードです。これは、イグナシの:
\begin{forest}
state tree,
[x_0
[x_1
[x_{11}
[x_{111}]
[\dot{\cup}]
[x_{112}]
]
[\times]
[x_{12}
[x_{121}]
[\dot{\cup}]
[x_{122}]
]
]
[\dot{\cup}]
[x_2]
[\dot{\cup}]
[x_3
[x_{31}]
[\dot{\cup}]
[x_{32}]
[\dot{\cup}]
[x_{33}]
]
]
\end{forest}
state tree
スタイルを設定します。残りは自動なので、no edge
などは必要ありません。
これにより、次の結果が生成されます。
完全なコード:
\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{forest}
% ateb: addaswyd o ateb Ignasi: https://tex.stackexchange.com/a/351690/
\forestset{%
state tree/.style={%
for tree={
math content,
parent anchor=children,
child anchor=parent,
tier/.option=level,
calign=center,
},
where={>On>{n children}{2}}{
for nodewalk={
filter={children}{>On=!On=!&{n}{1}{n'}{1}}
}{no edge}
}{},
before computing xy={
where={isodd(n_children)}{
tempdima/.process={OOOw3+d{!n=1.s}{!n'=1.s}{n children}{(##2-##1)/(##3-1)}},
tempdimb/.option={!n=1.s},
for children={
s/.process={RROw3+d{tempdima}{tempdimb}{n}{##2+(##1*(##3-1))}}
},
}{},
},
},
}
\begin{document}
\begin{forest}
state tree,
[x_0
[x_1
[x_{11}
[x_{111}]
[\dot{\cup}]
[x_{112}]
]
[\times]
[x_{12}
[x_{121}]
[\dot{\cup}]
[x_{122}]
]
]
[\dot{\cup}]
[x_2]
[\dot{\cup}]
[x_3
[x_{31}]
[\dot{\cup}]
[x_{32}]
[\dot{\cup}]
[x_{33}]
]
]
\end{forest}
\end{document}
答え2
を試すこともできますforest
が、一部の子要素を正しく分散させる方法がわかりません。
\documentclass [multi=forest, border=2mm]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={math content}
[x_0
[x_1
[x_{11}
[x_{111}]
[\dot{\cup}, no edge]
[x_{112}]]
[\times, no edge]
[x_{12}
[x_{121}]
[\dot{\cup}, no edge]
[x_{122}]]]
[\dot{\cup}, no edge]
[x_2, no edge]
[\dot{\cup}, no edge]
[x_3
[x_{31}]
[\dot{\cup}, no edge]
[x_{32}, no edge]
[\dot{\cup}, no edge]
[x_{33}]]]
\end{forest}
\end{document}
更新: JLDiaz の提案により、結果はより良くなりました。まだ完璧ではありませんが、より良くなりました。
\documentclass [multi=forest, border=2mm]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={math content}
[x_0
[x_1
[x_{11}
[x_{111}]
[\dot{\cup}, no edge]
[x_{112}]]
[\null, no edge] %<-------------
[\times, no edge]
[x_{12}
[x_{121}]
[\dot{\cup}, no edge]
[x_{122}]]]
[\null, no edge] %<-------------
[\dot{\cup}, no edge]
[x_2, no edge]
[\dot{\cup}, no edge]
[x_3
[x_{31}]
[\dot{\cup}, no edge]
[x_{32}, no edge]
[\dot{\cup}, no edge]
[x_{33}]]]
\end{forest}
\end{document}
答え3
最初の試みは次のようになります。私はツリーを描くのにあまり慣れていないので、これを行うにはもっと良い方法があるかもしれません。ただし、重要な点は子の間にノードを配置することであり、ライブラリはcalc
これに最適です。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\rootname{root}
\newcommand{\stnode}[3]{\node at ($(#1)!0.5!(#2)$) { #3 }}
\newcommand{\stnodec}[3]{\node at ($(#1.center)!0.5!(#2.center)$) { #3 }}
\newcommand{\stnoderootc}[3]{\node at ($(\rootname-#1.center)!0.5!(\rootname-#2.center)$) { #3 }}
\begin{document}
\begin{tikzpicture}
[
level 1/.style = {sibling distance = 3cm},
level 2/.style = {sibling distance = 2cm}
]
\node (root) { $x_0$ }
child { node { $x_1$ }
child { node { $x_3$ } }
child { node { $x_4$ } }
}
child { node { $x_2$ }
child { node { $x_5$ } }
child { node { $x_6$ } }
}
;
place the annotation nodes between the children
\stnode{root-1.center}{root-2.center}{$\times$};
\stnodec{root-1-1}{root-1-2}{$\times$};
\stnoderootc{2-1}{2-2}{$\times$};
\end{tikzpicture}
\end{document}
3つのマクロ(\stnode
、\stnodec
)のいずれかを使用できます。c注釈ノードを配置するには、\stnoderootc
(自動ルート ノード、中央))を使用します。ルート名は、ルート ノードの実際の名前を表すように再定義する必要があります。柔軟性を最大限に高めるには、 を使用します\stnode
。
引数は、#1: 最初のノード、#2: 2 番目のノード、#3: ノード テキストです。
当然、それぞれのノードは同じ y 配置を持つ必要があります。そうでなくても動作しますが、見た目が奇妙になります。