有没有办法根据边界矩形的左/右坐标来定位节点?在我看来,我只能指定中心位置。
答案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}