The TikZ/PGF documentation (v 2.10) contains the following example for the use of local bounding box
:
\documentclass{article}
\usepackage{tikz}
\usepgfmodule{shapes}
\usetikzlibrary{scopes}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,2);
{ [local bounding box=outer box]
\draw (1,1) circle (.5) [local bounding box=inner box] (2,2) circle (.5);
}
\draw (outer box.south west) rectangle (outer box.north east);
\draw[fill,red] (inner box.south west) rectangle (inner box.north east);
\end{tikzpicture}
\end{document}
– actually just the tikzpicture
, I made it into a complete document. This works as advertised until I explicitly set a global bounding box:
\documentclass{article}
\usepackage{tikz}
\usepgfmodule{shapes}
\usetikzlibrary{scopes}
\begin{document}
\begin{tikzpicture}
\path[use as bounding box] (-1,-1) rectangle (4,3); % <------------
\draw [help lines] (0,0) grid (3,2);
{ [local bounding box=outer box]
\draw (1,1) circle (.5) [local bounding box=inner box] (2,2) circle (.5);
}
\draw (outer box.south west) rectangle (outer box.north east);
\draw[fill,red] (inner box.south west) rectangle (inner box.north east);
\end{tikzpicture}
\end{document}
– then the two drawn outlines of outer box
and inner box
disappear. Changing \draw
to \fill
indicates that the boxes have become huge and cover the whole page and more.
My question: How do I get this to work? Is this a known bug with a workaround?
My goal in using local bounding box
is to measure the width and height of part of a TikZ figure using Caramdir's approach. In case local bounding box
is broken, what else can I do?
Best Answer
From the documentation of
/tikz/use as bounding box
:This is why you can't use
local bounding box
after it.But what you can do is to reset the bounding box after that, like this :
Here is the complete code: