tikz のテキスト ノードの座標は、ボックスの中心を指定します。ボックスの左端を指定する方法はありますか?

tikz のテキスト ノードの座標は、ボックスの中心を指定します。ボックスの左端を指定する方法はありますか?

対角線の右側にある 2 行のテキストを左揃えにしたいのですが、これを行う方法はありますか?

\begin{tikzpicture}

\node[text] at (2,4) {/p/};

\draw (2.5,4) -- (5,5);
\draw (2.5,4) -- (5,3);

\node[text,align=left] at (7.2,5) {\textipa{[b]} / [+voice] \_\_ [+voice]};
\node[text,align=left] at (6.5,3) {[p] / elsewhere};

\end{tikzpicture}

ここに画像の説明を入力してください

答え1

anchor=westボックスの位置を左端の点によって指定するには、 を使用するか、単に を使用することもできますright

\documentclass{article}
\usepackage{tikz}
\usepackage{tipa}
\begin{document}
\begin{tikzpicture}
 \node at (2,4) {/p/};
 \draw (2.5,4) -- (5,5) node[right,align=left] {\textipa{[b]} / [+voice] \_\_ [+voice]};
 \draw (2.5,4) -- (5,3) node[right,align=left] {[p] / elsewhere};
\end{tikzpicture}

\begin{tikzpicture}
 \node at (2,4) {/p/};
 \draw (2.5,4) -- (5,5) node[anchor=west,align=left] {\textipa{[b]} / [+voice] \_\_ [+voice]};
 \draw (2.5,4) -- (5,3) node[anchor=west,align=left] {[p] / elsewhere};
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

答え2

marmot の方法以外にも、これを行う方法はたくさんあります。ここではそのうちの 3 つを紹介します (将来、新しい方法を見つけたら追加します)。

方法1

\documentclass[tikz,margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[right] {Something} -- (-2,-1) node[left] {Dummy text} -- (0,-2) node[right] {Hello World};
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

直交座標の代わりに極座標を使うこともできます。また、この方法は非常に自然で(私はこの方法が好きです)、Tiを必要としません。Z ライブラリ。ただし、これは標準的な方法ではありません (\draw私の知る限り、このようなことを行うはずはありません)。

方法2

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (x) {Something};
\node[below left=1cm and 2cm of x.south west] (o) {Dummy text};
\node[below right=1cm and 2cm of o.south east] (y) {Hello World};
\draw (x.west)--(o.east)--(y.west);
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

この方法では、Tiに文字列を挿入するための標準コマンドを使用します。Z 画像:\nodeただし、テキストの位置合わせと位置の制御は、私見ではそれほど簡単ではありません。positioningライブラリが必要です。

方法3

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\coordinate[label=right: Something] (x);
\coordinate[label=right: Hello World,below=2cm of x] (y);
\coordinate[label=left: Dummy text,below left=1cm and 2cm of x] (o);
\draw (x)--(o)--(y);
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

この方法ではオプション\coordinate付きのコマンドを使用しますlabel

関連情報