Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Try putting \usetikzlibrary{scopes} into the preamble. –  Mark Wibrow Nov 16 '13 at 16:29
    
That removes the need for an explicit scope, but doesn't address my main problem. I'll remove the part about {} not working from the question, since apparently the manual example assumed to use this library. Thanks! –  A. Donda Nov 16 '13 at 16:32
    
I found a simple workaround: use a clipping path instead of use as bounding box. Not the same, but sufficient for my purposes. I'd still like to know why use as bounding box interferes with local bounding box. –  A. Donda Nov 16 '13 at 17:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.