[Tex/LaTex] Positioning a tikz scope relative to another tikz scope

pgfplotspositioningtikz-pgf

In the manual of PGFplots on page 333 the author describes how to position an axis environment relative to another axis environment:

\begin{tikzpicture}
    \begin{axis}[name=plot1,height=3cm,width=3cm]
        \addplot coordinates {(0,0) (1,1) (2,2)};
    \end{axis}
    \begin{axis}[name=plot2,at={($(plot1.east)+(1cm,0)$)},anchor=west,height=3cm,width=3cm]
         \addplot coordinates {(0,2) (1,1) (2,0)};
    \end{axis}
\end{tikzpicture}

Unfortunately, the same for scopes,

\begin{tikzpicture}
    \begin{scope}[name=scope1]
         \draw (1,2) rectangle (3,4);
    \end{scope}
    \begin{scope}[at={($(scope1.east)+(1cm,0)$)},anchor=west]
         \draw (5,6) rectangle (7,8);
    \end{scope}
\end{tikzpicture}

, does not work. How can I get it to work? I am not interested in absolute positioning, but merely in relative positioning.

Best Answer

Here is a solution using local bounding box to get the bounding box of the first scope and using shift to define the origin of the second scope:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \begin{scope}[local bounding box=scope1]
    \draw (2,2) rectangle (3,4);
  \end{scope}
  \begin{scope}[shift={($(scope1.east)+(1cm,0)$)}]
    \draw (0,0) rectangle (2,1);
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here