tikz:剪切范围的相对位置

unt*_*gam 2 layout latex scope tikz

我试图将一些tikz图组成一个更大的概览图,但是我很难将子图像相对于其父对象以及彼此对齐。

使用scope和从其他tikz图形中以矩形形状裁剪出子图像clip

红蓝色矩形

\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}
Run Code Online (Sandbox Code Playgroud)

目标是在相邻的灰色边界框内将红蓝色矩形很好地对齐(即,左,右和顶部的边距相等,底部有空间容纳文本)。

“边界条件”:内部限幅命令可能具有不同的x / y偏移量和大小,并且不能更改,但是它们具有已知的比率(在示例中为2:1)。我一直在尝试补偿xshiftyshiftscale内部作用域,但这并没有按预期工作。

内部作用域对象是裁剪所必需的,并且假定不能更改它们。外部范围是我解决问题的尝试,但不一定必须存在这些范围。

在网络上搜索时,我发现了以下相关链接,但是我无法通过内部作用域将它们中的任何一个适应我的用例。


编辑

澄清:我在内部范围内使用裁剪的原因主要是因为我想以特定方式裁剪子图像,而不是更改其位置。实际上,我希望对图像进行裁剪和缩放,但没有任何偏移。

我目前通过将子图像另存为png并在以后包含它们来达到期望的结果(也许这解释了为什么我不能更改内部剪辑的坐标,因为如果这样做,我将不得不更改所有子图像)

在此处输入图片说明

小智 5

您可以通过将嵌体移动到嵌入图片的某个锚点来对齐它们,例如shift={(scopeAouter.north)}。我也不会嵌套这些本地边界框。

\documentclass[crop,tikz]{standalone}

\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
    \end{scope}
    \begin{scope}[shift={(scopeAouter.north)}, scale=.5, local bounding box=scopeAinner]
        \clip [rounded corners=3] (-50, 10) rectangle ++(100, 50);
        % dummy pattern
        \fill [red!60] (-100,-100) rectangle (100, 100);
        \fill [blue!60] (-100, -100) -- (100, -100) -- (100, 100) -- cycle;
    \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
    \end{scope}
    \begin{scope}[shift={(scopeBouter.north)}, scale=1, local bounding box=scopeBinner]
        \clip [rounded corners=3] (-25, 5) rectangle ++(50, 25);
        % dummy pattern
        \fill [red!60] (-100,-100) rectangle (100, 100);
        \fill [blue!60] (-100, -100) -- (100, -100) -- (100, 100) -- cycle;
    \end{scope}

\end{tikzpicture}

\end{document}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

当然,我必须通过将坐标加倍来补偿相对比例因子。为什么使用不同的比例因子?