答案1
\path
只要图像的其余部分包含在其中,只需在两个角之间添加一个作为边界框就可以了。
更好的方法可能是使用宏明确固定边界框的大小\useasboundingbox
,该宏可以提供明确的坐标,或相对于另一个坐标的坐标,tikzpicture
如下所述这个答案。如果在边界框外面放置了某些东西(这可能是或可能不是所希望的),这将阻止边界框扩大。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (2,2) {Foo};
\draw (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}
\path (0,0) -- (5,5);
\node at (2,2) {Foo};
\draw (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle;
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle (5,5);
\node at (2,2) {Foo};
\node at (7,2) {Bar};
\draw (current bounding box.north east) -- (current bounding box.north west) -- (current bounding box.south west) -- (current bounding box.south east) -- cycle;
\end{tikzpicture}
\end{document}