tikz 中文字節點的座標指定框的中心。有沒有辦法讓它指定框的左邊緣?

tikz 中文字節點的座標指定框的中心。有沒有辦法讓它指定框的左邊緣?

我希望對角線右側的兩行文字左對齊。有什麼辦法可以做到這一點嗎?

\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

除了土撥鼠的方法之外,還有很多方法可以做到這一點。這是其中三個(如果將來找到一個我會添加更多)。

方法一

\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}

在此輸入影像描述

您可以使用極座標代替笛卡爾座標。而且,這種方式很自然(我更喜歡這種方式)並且不需要任何TikZ 庫。然而,這並不是一種標準方法(\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}

在此輸入影像描述

這種方式使用標準指令將字串插入 TikZ 圖片:\node.然而,恕我直言,要對齊文字和控制位置並不容易。你需要positioning圖書館。

方法三

\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

相關內容