如何缩放具有坐标输入的 tikz 图片?

如何缩放具有坐标输入的 tikz 图片?

如何缩放 tikz 图片而不缩放其坐标?在此示例中,我尝试先缩放图片,然后将其放在节点的左侧。但是,缩放命令\pgftransformscale{0.3}也会重新缩放坐标输入。也许我可以通过坐标计算来解决这个问题,但似乎有更好的方法。或者我应该使用其他东西而不是tikzset

\documentclass[border=10pt,multi,tikz]{standalone}

\usepackage{tikz} % Top and bottom rules for tables
\usetikzlibrary{arrows,calc,decorations.markings,math,arrows.meta, positioning}

\tikzset{boxstyle/.style = {draw, ultra thick, inner sep=0pt, minimum height=2cm}}
\tikzset{
  pics/colorvec/.style n args={3}{
    code = { %
        \pgfmathsetmacro{\valt}{#3-0.5}
        \pgfmathsetmacro{\valr}{#3*2}
        \node [boxstyle, minimum width=1cm, fill=#2] (chead) at ($#1+(0, 0)$) {};
        \node [boxstyle, minimum width=2cm, right=-0.06cm of chead] (elem1) {\small #3};
        \node [boxstyle, minimum width=2cm, right=-0.06cm of elem1] (elem2) {\small \valt};
        \node [boxstyle, minimum width=2cm, right=-0.06cm of elem2] (elem3) {\small \pgfmathprintnumber[assume math mode=true]{\valr}};
    }
  }
}

\begin{document}

\begin{tikzpicture}
%\draw [thin,dashed][help lines,step=1cm] (0,0) grid (30,10);
\node[draw] (node1) at (3, 3){Node};
%\pic[scale=0.1]{colorvec={(node1.east)}{blue}{0.2}};
\begin{pgflowlevelscope}{\pgftransformscale{0.3}}\pic{colorvec={(node1.east)}{blue}{0.2}};\end{pgflowlevelscope}

\node[draw] (node2) at (0, 0){Expand the canvas};

\end{tikzpicture}
\end{document} 

答案1

我假设您想对colorvec图片应用某个比例因子,并将其最左边的点放置在某个坐标上。如果我错了,请重新表述您的问题。

您的代码存在问题,即您如何放置chead元素。您使用元素的中心来放置它,因此它将始终覆盖用作参考的节点的一部分。如果您添加anchor=west选项chead,它的位置将位于第一个图片参数的右侧。

比例因子可应用于图片选项。

\documentclass[border=10pt,multi,tikz]{standalone}

\usepackage{tikz} % Top and bottom rules for tables
\usetikzlibrary{arrows,calc,decorations.markings,math,arrows.meta, positioning}

\tikzset{boxstyle/.style = {draw, ultra thick, inner sep=0pt, minimum height=2cm}}
\tikzset{
  pics/colorvec/.style n args={3}{
    code = { %
        \pgfmathsetmacro{\valt}{#3-0.5}
        \pgfmathsetmacro{\valr}{#3*2}
        \node [boxstyle, minimum width=1cm, fill=#2, anchor=west] (chead) at ($#1+(0, 0)$) {};
        \node [boxstyle, minimum width=2cm, right=-0.06cm of chead] (elem1) {\small #3};
        \node [boxstyle, minimum width=2cm, right=-0.06cm of elem1] (elem2) {\small \valt};
        \node [boxstyle, minimum width=2cm, right=-0.06cm of elem2] (elem3) {\small \pgfmathprintnumber[assume math mode=true]{\valr}};
    }
  }
}

\begin{document}
\begin{tikzpicture}
\node[draw] (node1) at (3, 3){Node};
\pic[scale=.3, transform shape]{colorvec={(node1.east)}{blue}{0.2}};
\node[draw] (node2) at (0, 0){Expand the canvas};
\end{tikzpicture}
\end{document} 

在此处输入图片描述

正如我已经说过的,我不知道这是否是预期的结果。我也不明白为什么 OP 不使用matrixorrectangle multipart而使用pic

相关内容