update i discovered lately this question where Nickolay Kolev uses \tikz
inside a tikzpicture environment. A lot of users think that is a wrong practice and I agree that is very strange but sometimes very useful. I agree too that it's preferable to avoid this kind of situation. I use this possibility in pgfornament
.
I don't understand why if I invert the two lines of the tikzpicture (the wrapper) I get different results. overlay
I think, resets the bounding box but why inside the second tikzpicture, the overlay resests the general bounding box.
When I use a scope, the problem disappears ?
update I suppose that tikz's experts think it's preferable to use a scope and the question is stupid ...
Or in the pgfmanual, I read
All graphic options are local to the {tikzpicture} to which they apply.
The picture in red has no bounding box.
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\begin{document}
baseline\begin{tikzpicture}[baseline=(current bounding box.north west)]
\tikz[overlay] \path (0,0) -- (1,1) node {\color{blue}$\bullet$};
\draw[help lines,blue!20] (0,0) grid (2,2) ;
\end{tikzpicture}baseline%
%
\begin{tikzpicture}[baseline=(current bounding box.south west)]
\draw[help lines,red!20] (0,0) grid (2,2) ;
\tikz[overlay] \path (0,0) -- (1,1) node {\color{red}$\bullet$};
\end{tikzpicture}baseline
\end{document}
With pgfinterruptboundingbox
Picture in green. The bounding box is correct. The first bounding box is protected.
The solution is to place the line with overlay inside a pgfinterruptboundingbox environment so the problem is linked to the current bounding box.
baseline\begin{tikzpicture}[baseline=(current bounding box.south west)]
\draw[help lines,green!50] (0,0) grid (2,2) ;
\begin{pgfinterruptboundingbox}
\tikz[overlay] \path (0,0) -- (1,1) node {\color{green}$\bullet$};
\end{pgfinterruptboundingbox}
\end{tikzpicture}baseline
No problem with a scope
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\begin{document}
baseline\begin{tikzpicture}[baseline=(current bounding box.north west)]
\tikz[overlay] \path (0,0) -- (1,1) node {\color{blue}$\bullet$};
\draw[help lines,blue!20] (0,0) grid (2,2) ;
\end{tikzpicture}baseline
\begin{tikzpicture}[baseline=(current bounding box.south west)]
\draw[help lines,red!20] (0,0) grid (2,2) ;
\begin{scope} [overlay] \path (0,0) -- (1,1) node {\color{red}$\bullet$};
\end{scope}
\end{tikzpicture}baseline
\end{document}
( What is the real differences between a scope and a tikzpicture ?)
update The question is perhaps too general, better is How tikz performs overlay
?