title: tikz: relative positioning of clipped scopes
body: <p>I am trying to compose some tikz diagrams into a larger overview chart, but I am having difficulties aligning the sub-images relatively to their parent objects and to each other.</p>
  
  <p>The sub-images are cropped out in rectangle shape from some other tikz graphic using <code>scope</code> and <code>clip</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/JvLM9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JvLM9.png" alt="red-blue rectangles"></a></p>
  
  <pre class="lang-latex prettyprint-override"><code>\documentclass[crop,tikz]{standalone}
  \usepackage{relsize, xcolor, tikz}
  
  \begin{document}
  
  \begin{tikzpicture}[x=0.04cm,y=-0.04cm]
  
      \begin{scope}[xshift=0, yshift=0, local bounding box=scopeAouter]
          \fill [black!40, rounded corners=5] (0, 0) rectangle ++(60, 70);  % bounding rectangle
          \begin{scope}[xshift=0, yshift=0, scale=.5, local bounding box=scopeAinner]
              \clip [rounded corners=3] (-30, -5) rectangle ++(100, 50);  % cannot change this line
              % dummy pattern
              \fill [red!60] (-100,-100) rectangle (100, 100);
              \fill [blue!60] (-100, -100) -- (100, -100) -- (100, 100) -- cycle;
          \end{scope}
      \end{scope}
  
      \begin{scope}[xshift=80, yshift=0, local bounding box=scopeBouter]
          \fill [black!40, rounded corners=5] (0,0) rectangle ++(60, 70);  % bounding rectangle
          \begin{scope}[xshift=0, yshift=0, scale=1, local bounding box=scopeBinner]
              \clip [rounded corners=3] (4, 2) rectangle ++(50, 25);  % cannot change this line
              % dummy pattern
              \fill [red!60] (-100,-100) rectangle (100, 100);
              \fill [blue!60] (-100, -100) -- (100, -100) -- (100, 100) -- cycle;
          \end{scope}
      \end{scope}
  
  \end{tikzpicture}
  
  \end{document}
  </code></pre>
  
  <p>The goal is to align the red-blue rectangles nicely inside neighboring grey bounding boxes (i.e. equal margins on left, right and top, with room for text in the bottom).</p>
  
  <p>"boundary conditions": The inner clipping commands have potentially different x/y offsets and sizes and <strong>cannot be changed</strong>, but they have a known ratio (2:1 in the example). I've been trying to compensate with the <code>xshift</code>, <code>yshift</code> and <code>scale</code> of the inner scopes but that didn't work as expected.</p>
  
  <p>The inner scope objects are required for cropping and the assumption is that they cannot be changed. The outer scopes were my attempt to solve the problem but they do not necessarily need to be there.</p>
  
  <p>Searching the web I found the following relevant links, but I was not able to adapt any of them to my use case with an inner scope.</p>
  
  <ul>
  <li><a href="//tex.stackexchange.com/q/144402">Positioning a tikz scope relative to another tikz scope</a></li>
  <li><a href="//tex.stackexchange.com/q/133313">Shifting nested tikz scopes with a command</a></li>
  <li><a href="//tex.stackexchange.com/q/362307">Best practice for creating TikZ pictures with nested elements</a></li>
  </ul>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Clarification: The reason I use clipping in the inner scopes is essentially because I want to crop the sub-images in a particular way, not to change their position. In fact, I want the images cropped and scaled, but without any offset.</p>
  
  <p>I am currently achieving the desired result by saving the sub-images as pngs and including them later (maybe this explains why I cannot change the coordinates of the inner clips, because if I did I would have to change all sub-images)</p>
  
  <p><a href="https://i.stack.imgur.com/owdJp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/owdJp.png" alt="enter image description here"></a> </p>