将节点锚定在 tikzpicture 的角落

将节点锚定在 tikzpicture 的角落

如何在不明确设置位置的情况下将节点定位在 tikzpicture 的左上角?

是否有任何相对于 tikzpicture“框架”本身定位的钩子(并且在一般情况下有效)?

答案1

节点就是包含该点current bounding box内容的节点。因此,是左上角。当然,如果您向图表中添加新元素,边界框可能会发生变化。tikzpicturecurrent bounding box.north west

一个简单的例子:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\fill (0,0) circle[radius=3pt];
\fill (2,3) circle[radius=3pt];

\node [draw,below right] at (current bounding box.north west) {top left};
\draw [red] (current bounding box.south east) rectangle (current bounding box.north west);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容