
有沒有辦法根據邊界矩形的左/右座標來定位節點?在我看來,我只能指定中心位置。
答案1
如果要在給定座標處左對齊或右對齊節點,請在節點上使用anchor = east
/選項。anchor=west
以下是居中、右對齊和左對齊的範例:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[framed]
\useasboundingbox (0,0) rectangle (4,4);
\node at (2,2) {gnarply};
\draw (2,2)--(3,3);
\end{tikzpicture}\qquad
\begin{tikzpicture}[framed]
\useasboundingbox (0,0) rectangle (4,4);
\node[anchor=west] at (2,2) {gnarply};
\draw (2,2)--(3,3);
\end{tikzpicture}\qquad
\begin{tikzpicture}[framed]
\useasboundingbox (0,0) rectangle (4,4);
\node[anchor=east] at (2,2) {gnarply};
\draw (2,2)--(3,3);
\end{tikzpicture}
\end{document}