
中括弧 {} 内にノードを定義しようとしています:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\Tree [.CP \node(y){here}; [.C$'$ C [.TP \edge[roof]; {Some text \node(x){here};} ]]]
\end{tikzpicture}
\end{document}
tikz-qtree が文字列「Some text here」を単一の単位として扱うようにしたいので、{} 環境内でノード x を定義する必要があります。ただし、最初または 2 番目の閉じ括弧の後にセミコロンを置くと、機能しません。
答え1
屋根付きノード内のテキストは内部的にはノード自体であり、ノード内にノードを埋め込むことはできないため、この問題には少し異なる方法で対処する必要があります。基本的な考え方は、屋根付きノードの親ノードを名前付きノードにすることです。次に、たとえば各ノードからの矢印を表示したい場合は、矢印の開始点を親ノードに対してオフセットする必要があります。次に例を示します。
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\Tree [.CP \node(y){here}; [.C$'$ C [.\node(x){TP}; \edge[roof]; {Some text here} ]]]
\draw [->] (x.south)++(.9,-1) to[out=-90,in=-90,looseness=2] (y.south);
\end{tikzpicture}
\end{document}
別の方法 (おそらく少し簡単です) は、屋根のテキスト自体をノードとして定義し、パラメータを使用して[xshift]
矢印の開始点を目的の場所に移動するだけです。
\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}
\begin{tikzpicture}
\Tree [.CP \node(y){here}; [.C$'$ C [.TP \edge[roof]; \node(x){Some text here}; ]]]
\draw [->] ([xshift=2.5em]x.south) to[out=-90,in=-90,looseness=2] (y.south);
\end{tikzpicture}
\end{document}
答え2
万が一、誰にも気づかれなかった場合に備えて言っておくと、私はforest
木を描くときに好む傾向があります。
この解決策では、「ここ」という単語を手動で繰り返したり、矢印の開始位置を手動で調整したりする必要はありません。マニュアルの 20 ページの例に基づいていますが、少し間違っている可能性があります。
triangle
屋根に使用される- スタイルは
move={}{}
2 つの引数を取るように定義されています。最初の引数はコンテンツのコピー先のノードを指定し、2 番目の引数は現在のノードに追加する追加のテキストを指定します。
これを正確に実行したくないと思うかもしれないので、これはすぐに使用できるソリューションというよりは、説明のためのものです。あなたが示した例では、 と入力し、move={<specification of target node>}{Some text}
ソース ノードのコンテンツを として指定しますhere
。
すると、ソース ノードには が含まれSome text here
、ターゲット ノードには が含まれ、ソース ノードのすぐ下の点とターゲット ノードのすぐ下のhere
点の間に矢印が描画されます。here
here
ターゲット ノードを指定するために、「相対ノード ウォーク」を使用しました。ただし、, name=target
ターゲット ノードに を追加してから と入力するだけでも同じように実行できますmove={target}{Some text}
。ほとんどの場合、この方法の方が簡単でしょう。このアイデアを示すために、ツリーにコメント付きコードとしてこの代替案を追加しました。
\documentclass[tikz,border=5pt]{standalone}
\usepackage{forest}
\begin{document}
\newlength{\sourcetextaddwidth}
\begin{forest}
for tree={
parent anchor=south,
child anchor=north,
fit=rectangle
},
move/.style n args=2{% page 20 of forest manual
before typesetting nodes={
TeX={
\settowidth{\sourcetextaddwidth}{#2}
},
#1.content={##1},
content={#2 ##1},
tikz={
\draw[->] (.south) +(.5\sourcetextaddwidth,0) to [out=south west, in=south] (#1);
},
},
},
[CP
[this is the target node to which text will be moved%, name=target
]
[C$'$
[C
]
[TP
[here, triangle, move={!r1}{Some text}% move={target}{Some text}
]
]
]
]
\end{forest}
\end{document}