每张图片的缩放问题(角度 tikzlibrary)

每张图片的缩放问题(角度 tikzlibrary)

大家好,我需要缩放 tikzpicture,所以我按照以下方法操作,\begin{tikzpicture}[scale=<factor>]但图片没有相应缩放(据 TikzManual 报道18.2 Pic 语法)。我也想缩放图片,所以我尝试了语法,\begin{tikzpicture}[scale=0.4,every pic/.style={transform shape}]但没有成功。使用变换形状作为每张图片的选项,即,\pic[angle radius=5.3cm,transform shape]这是可以的,但我不想在\pics 的每个选项上使用它。也许这只是角度库的问题(我没有尝试其他图片)。这是我的 MWE,它没有按预期工作

    \documentclass[border=1cm]{standalone}
    \usepackage{tikz}
    \usetikzlibrary{calc,angles}
    \begin{document}
    %rotate vectors
\begin{tikzpicture}[vector/.style={thick,-stealth},scale=0.4,every pic/.style={transform shape}]
%drawing help lines
\newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
\newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
\draw[help lines](\xmin,\ymin)grid(\xmax,\ymax);
%vector coordinates and labels
\coordinate[label={above:$v$}] (O)at (0,0);
\coordinate (vec1)at (1,-2);
\coordinate (vec2)at(4,-1);
\draw[vector] (O)--(vec1)coordinate[label={[below]$u_1$}](u1);
%sum (vec1)+(vec2)  
\draw[vector,very thick,blue](O)--($(vec1)+(vec2)$)coordinate(u1+u2);
%rotated sum (u1)+(u2) -> u'1+u'2
\draw[vector,very thick,orange](O)--([rotate=-90]u1+u2)coordinate(u'1+u'2);
%rotated vectors 
\draw[red,vector] (0,0)--([rotate=-90]vec1)coordinate[label={[left]$u'_1$}](u'1); 
%
\draw[red,vector] (0,0)--([rotate=-90]vec2)coordinate[label={[below]$u'_2$}](u'2);
%angles between vectors by angles library, issue with angle radius=  
%default angle radius=1cm and it does not scale accordingly
\pic[draw=gray] {angle = u'1--O--u'2};  
% rotation traces 
\pic[draw=red,dashed,<-,angle radius=1.8cm]{angle=u'1--O--vec1}; 
\pic[draw=blue,dashed,<-,angle radius=5.3cm,]  {angle=u'1+u'2--O--u1+u2}; 
%vector sums labels 
\coordinate[label={below:$w$}]() at(u1+u2);
\coordinate[label={below:$w'$}] ()at(u'1+u'2);
  % outgoing vector scaled accordingly but I'd rather prefer not
    \path[draw,fill=white] (O)circle[radius=2pt];
    \path[fill] (O)circle[radius=1pt];
    \end{tikzpicture}\end{document}

虚线弧应按比例缩放以适合箭头

下面这个可以正常工作,

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles}
\begin{document}
%
%rotate vectors
\begin{tikzpicture}[vector/.style={thick,-stealth},scale=0.4 ] %every pic/.append style={transform shape}
%drawing help lines
\newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
\newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
\draw[help lines](\xmin,\ymin)grid(\xmax,\ymax);
%vector coordinates and labels
\coordinate[label={above:$v$}] (O)at (0,0);
\coordinate (vec1)at (1,-2);
\coordinate (vec2)at(4,-1);
\draw[vector] (O)--(vec1)coordinate[label={[below]$u_1$}](u1);
%sum (vec1)+(vec2)  
\draw[vector,very thick,blue](O)--($(vec1)+(vec2)$)coordinate(u1+u2);
%rotated sum (u1)+(u2) -> u'1+u'2
\draw[vector,very thick,orange](O)--([rotate=-90]u1+u2)coordinate(u'1+u'2);
%rotated vectors 
\draw[red,vector] (0,0)--([rotate=-90]vec1)coordinate[label={[left]$u'_1$}](u'1); 
%
\draw[red,vector] (0,0)--([rotate=-90]vec2)coordinate[label={[below]$u'_2$}](u'2);
%angles between vectors by angles library, issue with angle radius=  
%default angle radius=1cm and it does not scale accordingly
\pic[transform shape,draw=gray] {angle = u'1--O--u'2};  
% rotation traces 
\pic[draw=red,dashed,<-,angle radius=1.8cm,transform shape]{angle=u'1--O--vec1}; 
\pic[transform shape,draw=blue,dashed,<-,angle radius=5.3cm,]  {angle=u'1+u'2--O--u1+u2}; 
%vector sums labels 
\coordinate[label={below:$w$}]() at(u1+u2);
\coordinate[label={below:$w'$}] ()at(u'1+u'2);

    % outgoing vector scaled accordingly but I'd rather prefer not
    \path[draw,fill=white] (O)circle[radius=2pt];
    \path[fill] (O)circle[radius=1pt];
\end{tikzpicture}
\end{document}

在此处输入图片描述

也许有更好的方法来实现这一点,我对此持开放态度,但我不会从头开始更改我的代码。

我尝试过every pic/.append style={transform shape},但没有明显的效果。副作用是半径传出向量代码的最后几行被缩放,这是我不想要的。

答案1

由于您想要向每个 附加一种样式\pic{angle},因此您可以设置pics/angle/.append style={/tikz/transform shape}(您需要明确说明路径,因为您在\pic此处的“路径目录”内):

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, angles}

\begin{document}
%rotate vectors
\begin{tikzpicture}[
    vector/.style={thick,-stealth}, 
    scale=0.4, 
    pics/angle/.append style={/tikz/transform shape}
]
    %drawing help lines
    \newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
    \newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
    \draw[help lines] (\xmin,\ymin) grid (\xmax,\ymax);
    %vector coordinates and labels
    \coordinate[label={above:$v$}] (O) at (0,0);
    \coordinate (vec1) at (1,-2);
    \coordinate (vec2) at (4,-1);
    \draw[vector] (O) -- (vec1)
        coordinate[label={[below]$u_1$}] (u1);
    %sum (vec1)+(vec2)  
    \draw[vector,very thick,blue] (O)--($(vec1)+(vec2)$)
        coordinate (u1u2);
    %rotated sum (u1)+(u2) -> u'1+u'2
    \draw[vector,very thick,orange] (O)--([rotate=-90]u1u2)
        coordinate (u'1u'2);
    %rotated vectors 
    \draw[red,vector] (0,0) -- ([rotate=-90]vec1)
        coordinate[label={[left]$u'_1$}] (u'1);
    %
    \draw[red,vector] (0,0) -- ([rotate=-90]vec2)
        coordinate[label={[below]$u'_2$}] (u'2);
    %angles between vectors by angles library, issue with angle radius=  
    %default angle radius=1cm and it does not scale accordingly
    \pic[draw=gray] {angle={u'1--O--u'2}};
    % rotation traces 
    \pic[draw=red, dashed, <-, angle radius=1.8cm] {angle={u'1--O--vec1}};
    \pic[draw=blue, dashed, <-, angle radius=5.3cm] {angle={u'1u'2--O--u1u2}};
    %vector sums labels 
    \coordinate[label={below:$w$}] (w) at (u1u2);
    \coordinate[label={below:$w'$}] (w') at (u'1u'2);
    % outgoing vector scaled accordingly but I'd rather prefer not
    \path[draw, fill=white] (O) circle[radius=2pt];
    \path[fill] (O) circle[radius=1pt];
\end{tikzpicture}
\end{document}

在此处输入图片描述

我更改了一些坐标名称,因为我不确定+名称中是否包含 是个好主意。您可以自行决定是否遵守这一点。


如果您不想(O)缩放 处的圆,请\pic从此处创建一个。我们知道\pic不受缩放的影响,并且仅pics/angle/.append style={/tikz/transform shape}应用于。transform shape\pic{angle}

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, angles}

\begin{document}
%rotate vectors
\begin{tikzpicture}[
    vector/.style={thick,-stealth}, 
    scale=0.4, 
    pics/angle/.append style={/tikz/transform shape},
    pics/origin/.style={
        code={
            \path[draw, fill=white] (0,0) circle[radius=2pt];
            \path[fill] (0,0) circle[radius=1pt];
        }
    }
]
    %drawing help lines
    \newcommand*{\xmin}{-3}\newcommand*{\xmax}{4}
    \newcommand*{\ymin}{-5}\newcommand*{\ymax}{1}
    \draw[help lines] (\xmin,\ymin) grid (\xmax,\ymax);
    %vector coordinates and labels
    \coordinate[label={above:$v$}] (O) at (0,0);
    \coordinate (vec1) at (1,-2);
    \coordinate (vec2) at (4,-1);
    \draw[vector] (O) -- (vec1)
        coordinate[label={[below]$u_1$}] (u1);
    %sum (vec1)+(vec2)  
    \draw[vector,very thick,blue] (O)--($(vec1)+(vec2)$)
        coordinate (u1u2);
    %rotated sum (u1)+(u2) -> u'1+u'2
    \draw[vector,very thick,orange] (O)--([rotate=-90]u1u2)
        coordinate (u'1u'2);
    %rotated vectors 
    \draw[red,vector] (0,0) -- ([rotate=-90]vec1)
        coordinate[label={[left]$u'_1$}] (u'1);
    %
    \draw[red,vector] (0,0) -- ([rotate=-90]vec2)
        coordinate[label={[below]$u'_2$}] (u'2);
    %angles between vectors by angles library, issue with angle radius=  
    %default angle radius=1cm and it does not scale accordingly
    \pic[draw=gray] {angle={u'1--O--u'2}};
    % rotation traces 
    \pic[draw=red, dashed, <-, angle radius=1.8cm] {angle={u'1--O--vec1}};
    \pic[draw=blue, dashed, <-, angle radius=5.3cm] {angle={u'1u'2--O--u1u2}};
    %vector sums labels 
    \coordinate[label={below:$w$}] (w) at (u1u2);
    \coordinate[label={below:$w'$}] (w') at (u'1u'2);
    % outgoing vector scaled accordingly but I'd rather prefer not
    \pic at (O) {origin};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容