3

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.

The sub-images are cropped out in rectangle shape from some other tikz graphic using scope and clip:

red-blue rectangles

\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}

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).

"boundary conditions": The inner clipping commands have potentially different x/y offsets and sizes and cannot be changed, but they have a known ratio (2:1 in the example). I've been trying to compensate with the xshift, yshift and scale of the inner scopes but that didn't work as expected.

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.

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.


Edit

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.

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)

enter image description here

3
  • Just to understand the problem: the subimages that you want to crop are for example the cars in your image? Oct 24, 2019 at 7:57
  • No, the sub-images are the entire scene (consisting of cars, roads, arrows, lane markings, etc) - or equivalently the red-blue rectangles from the minimal working example. Cropping and scaling of the sub-images works well, just positioning does not.
    – mattu
    Oct 24, 2019 at 21:21
  • Ah, now it makes sense. Thanks for the clarification! Oct 24, 2019 at 21:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.