3

I currently try to create a tikzpicture with multiple scopes. The scopes should be positioned relative to each other, so I use "local bounding box=..." for each scope to access their sizes.

My Problem: The corner positions of the bounding boxes are not known before drawing and not necessarily at (0,0), because my final content cannot be drawn by starting at a corner. (I have to start somewhere in the center of the scopes final bounding box.)

So my main question is: How to shift a scopes local bounding box so that its bottom left corner is positioned at (0,0), not knowing the bounding box corners before drawing its content?

Because then I can easily position the scopes/bounding boxes relative to each other.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\newcommand{\A}{
  \begin{scope}[local bounding box=A]
    \node[blue] at (0, 0) {A};
  \end{scope}
}
\newcommand{\B}{
  \begin{scope}[local bounding box=B]
    \node[red] at (-1, 0) {B};
  \end{scope}
}
\begin{document}

% Problem: Bounding box B should be positioned as if its bottom left corner starts at (0, 0). The bounding box B is not known before drawing, so the solution below does not work in general.
\begin{tikzpicture}
    \A
    \begin{scope}[shift={(A.east)}]
        \B
    \end{scope}
\end{tikzpicture}

% Desired Result: (With shift=(1, 0) just to demonstrate the desired result.)
\begin{tikzpicture}
    \A
    \begin{scope}[shift={(A.east)}, shift={(1, 0)}]
        \B
    \end{scope}
\end{tikzpicture}

\end{document}

Resulting tikzpicture:

Left (B A): problem; Right (AB): desired result tikzpicture

slbb
  • 31

0 Answers0