
タイムライン用の次の LaTeX コード ( を使用) がありますtree
が、「no」ボックスの後の 2 つの空のボックスを非表示にして、代わりに action3 への直線矢印のみを表示したいと思います。次のようになります。
yes -> action1 -> action2 -> action3
no -----------------------> action3
コードは次のとおりです:
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees,arrows}
\begin{document}
\begin{tikzpicture}[level distance=1in,sibling distance=.25in,scale=.65]
\tikzset{edge from parent/.style=
{thick, draw, -latex,
edge from parent fork right},
every tree node/.style={draw,minimum width=0.7in,text width=0.7in, align=center},grow'=right}
\Tree
[. {do?}
[. {yes }
[. {action1}
[. {action2}
[. {action3}
]
]
]
]
[. {no }
[. {}
[. {}
[. {action3}
]
]
]
]
]
\end{tikzpicture}
\end{document}
答え1
答え2
お二人ともありがとうございます。質問を投稿した後に思いついた解決策は次のとおりです: (注: コードでは、はいといいえも矢印の上に移動しています) (また、追加の中間矢印の端を避けるために \edge[-] コマンドにも注意してください)
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees,arrows}
\begin{document}
\begin{tikzpicture}[level distance=1.5in,sibling distance=.25in,scale=.65]
\tikzset{edge from parent/.style={thick, draw, -latex, edge from parent fork right},
every tree node/.style={draw,minimum width=0.7in,minimum height=0.65in,text width=0.7in, align=center},grow'=right}
\Tree
[. \node {do?};
\edge node[above, pos=0.7] {yes};
[. {action1}
[. {action2}
[. {action3} ]
]
]
\edge[-] node[below, pos=0.6] {no};
[
\edge[-] {};
[
\edge {};
[. {action3} ]
]
]
]
\end{tikzpicture}
\end{document}
答え3
答え4
の1つの利点は森tier
これを使用すると、一部のノードに他のノードよりも多くの介在ノードがある場合でも、特定のノードがツリーの同じレベルにある必要があることをパッケージに指示できます。
例えば、以下のコードでは
if n children=0{tier=terminums}{},
終端ノードはすべてツリーの同じ層に配置する必要があることを示しています。したがって、祖先が少ないノードにダミーノードを作成する必要なく、2 アクション 3 ノードを配置できます。
スタイルは、エッジ上のおよびラベルlabel me={}{}
の配置を容易にするために作成されます。最初の引数はラベル ノードのオプションに追加され、相対位置 (例 )やアンカー (例) などを指定するために使用できます。2 番目の引数はラベルの内容を指定します。yes
no
above right
anchor=north west
このパッケージの大きな利点は、スタイルを設定したら、ツリーを非常に簡潔に指定できることです。例:
[do?
[action 1, label me={above, anchor=south west}{yes}
[action 2
[action 3]
]
]
[action 3, label me={below, anchor=north west}{no}]
]
生産する
完全なコード:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
label me/.style n args=2{
delay={edge label/.wrap value={node [midway, #1, font=\scriptsize] {#2}}}
},
for tree={
grow'=0,
draw,
text width=15mm,
minimum height=7mm,
parent anchor=east,
child anchor=west,
edge={->},
text centered,
edge path={
\noexpand\path [\forestoption{edge}] (!u.parent anchor) -- +(3mm,0) |- (.child anchor)\forestoption{edge label};
},
if n children=0{tier=terminums}{},
l sep+=5mm,
}
[do?
[action 1, label me={above, anchor=south west}{yes}
[action 2
[action 3]
]
]
[action 3, label me={below, anchor=north west}{no}]
]
\end{forest}
\end{document}