作用域命令问题

作用域命令问题

我有一个 latex 文档,其中我绘制了一个带有两个 tikzpictures 的图形,我需要将这两个 tikzpictures 放置在特定位置。为此,我使用了带有“ ”的“scope”命令shift=。在我的文档中,tikzpictures 使用“ ”命令缩放scalebox,后者带来了一个问题,它在要绘制的图形之前留下了一个空格,当我删除“scalebox”命令时,我得到了所需的结果,但我必须使用“scalebox”命令。

下面是一个小例子(不是我的例子)

\documentclass{book}
\usepackage{tikz}
\usepackage{float}
\begin{document}
dhdghg hdg hdgh dghg g dhdhfghdgfdhgfhdfghdfghfg hdfghgfhffh dghfgdhfdhfgdhfgdhfgdhh d hfg dh gdhf gdh fghdgfdhgfh hfgdhfg hdgf 
\begin{figure}[H]
\begin{tikzpicture}
\scalebox{0.4}{%
\draw (0,0) rectangle (8,16);
}
\scalebox{0.85}{%
\begin{scope}[shift={(6,3)},scale=0.85]
\draw[red,line width=1.2pt] (0,0) rectangle (3,4);
\end{scope}}
\end{tikzpicture}
\end{figure}
dhdghg hdg hdgh dghg g dhdhfghdgfdhgfhdfghdfghfg hdfghgfhffh dghfgdhfdhfgdhfgdhfgdhh d hfg dh gdhf gdh fghdgfdhgfh hfgdhfg hdgf 
\end{document}

在此处输入图片描述

当我使用“ scale=”时,一些绘图(带有锯齿状装饰的绘图)不会缩放。我再举一个例子。

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, patterns,decorations.markings,shadings,decorations.shapes}
\usepackage{float}

\begin{document}
dhdghg hdg hdgh dghg g dhdhfghdgfdhgfhdfghdfghfg hdfghgfhffh dghfgdhfdhfgdhfgdhfgdhh d hfg dh gdhf gdh fghdgfdhgfh hfgdhfg hdgf 
\begin{figure}[H]
\begin{tikzpicture}
\begin{scope}[scale=0.4]
\draw (0,0) rectangle (8,16);
\end{scope}

\begin{scope}[shift={(-10,2)}]
\draw[line width=1.2pt,color=black] (3,1.5)--(1,1.5)--(1,2.2)--(3,2.2)--cycle;
\draw[line width=1.2pt] (1.1,2.4)--(2.9,2.3);
\draw[line width=1.2pt] (1.2,2.9)--(2.8,2.8);
\draw[line width=1.2pt] (1.24,3.4)--(2.74,3.3);
\draw[line width=1.2pt] (1.3,3.9)--(2.68,3.8);
\draw[line width=1.2pt] (1.37,4.4)--(2.62,4.3);
\draw[line width=1.2pt] (1.43,4.9)--(2.54,4.8);
\draw[line width=1.2pt] (1.5,5.38)--(2.48,5.28);
\draw[line width=1.2pt] (1.56,5.88)--(2.42,5.78);
\draw[line width=1.2pt] (1.64,6.38)--(2.36,6.28);
\draw[line width=1.2pt] (1.7,6.88)--(2.3,6.78);
\draw[line width=1.2pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (3,2.2)--(2.35,7);
\draw[line width=1pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (1.65,7)--(1,2.2);
\end{scope}

\begin{scope}[scale=0.3,shift={(-10,2)}]
\draw[line width=1.2pt,color=black] (3,1.5)--(1,1.5)--(1,2.2)--(3,2.2)--cycle;
\draw[line width=1.2pt] (1.1,2.4)--(2.9,2.3);
\draw[line width=1.2pt] (1.2,2.9)--(2.8,2.8);
\draw[line width=1.2pt] (1.24,3.4)--(2.74,3.3);
\draw[line width=1.2pt] (1.3,3.9)--(2.68,3.8);
\draw[line width=1.2pt] (1.37,4.4)--(2.62,4.3);
\draw[line width=1.2pt] (1.43,4.9)--(2.54,4.8);
\draw[line width=1.2pt] (1.5,5.38)--(2.48,5.28);
\draw[line width=1.2pt] (1.56,5.88)--(2.42,5.78);
\draw[line width=1.2pt] (1.64,6.38)--(2.36,6.28);
\draw[line width=1.2pt] (1.7,6.88)--(2.3,6.78);
\draw[line width=1.2pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (3,2.2)--(2.35,7);
\draw[line width=1pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (1.65,7)--(1,2.2);
\end{scope}
\end{tikzpicture}
\end{figure}
dhdghg hdg hdgh dghg g dhdhfghdgfdhgfhdfghdfghfg hdfghgfhffh dghfgdhfdhfgdhfgdhfgdhh d hfg dh gdhf gdh fghdgfdhgfh hfgdhfg hdgf 
\end{document}

在此处输入图片描述

答案1

scale{0.4}将所有坐标乘以给定的 0.4,但不包括图片,

  • 我们可以手动修改segment length = 0.2mm(5mm x 0.4)和amplitude = 0.4mm(1mm x 0.4)

  • 使用transform canvas={scale=0.4}

     \documentclass{article}
     \usepackage{tikz}
     \usetikzlibrary{decorations.pathmorphing, patterns,decorations.markings,shadings,decorations.shapes}
     \begin{document}
     \tikzset{
         line width=1.2pt,
         pics/piczigzag/.style={
                 code={
                         \draw(3,1.5)--(1,1.5)--(1,2.2)--(3,2.2)--cycle;
                         \draw  (1.1,2.4)--(2.9,2.3);
                         \draw  (1.2,2.9)--(2.8,2.8);
                         \draw  (1.24,3.4)--(2.74,3.3);
                         \draw  (1.3,3.9)--(2.68,3.8);
                         \draw  (1.37,4.4)--(2.62,4.3);
                         \draw  (1.43,4.9)--(2.54,4.8);
                         \draw  (1.5,5.38)--(2.48,5.28);
                         \draw  (1.56,5.88)--(2.42,5.78);
                         \draw  (1.64,6.38)--(2.36,6.28);
                         \draw  (1.7,6.88)--(2.3,6.78);
                         \draw[line width=1pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (3,2.2)--(2.35,7);
                         \draw[line width=1pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (1.65,7)--(1,2.2);
                     },
             }
     }
     %  with scale, don't work, Multiplies all coordinates by the given hfactori but not the ndoe th pic, 
     % \begin{tikzpicture}
     % \pic [red] at (0,0) {piczigzag};
     % \pic[scale=0.4,blue] at (4,0) {piczigzag};
     % \end{tikzpicture}
    
     \begin{tikzpicture}
         \pic [red] at (0,0) {piczigzag};
         \pic[transform canvas={scale=0.4},blue] at (10,0) {piczigzag};
     \end{tikzpicture}
    
     \end{document}
    

在此处输入图片描述

编辑:正如您所见,令人惊讶的是这些数字并不一致。

我从图片的原点和彩色图形的第一个可见点添加了一个网格和一条虚线。

在此处输入图片描述

红色图中 (1,1.5) 的偏移量在蓝色图中为 (0.4,0.6) 1 x 0.4 和 1.5 x 0.4

可以通过以下方式恢复这种情况:

  • 重新输入所有坐标...

  • 转移shift={(-1,-1.5)

     \pic [red,shift={(-1,-1.5)}] (A) at (0,0) {piczigzag};
     \pic[transform canvas={scale=0.4},blue,shift={(-1,-1.5)}] at (7,0) {piczigzag};
    

备注:坐标 (7,0) 对应于 (2.8,0) --> 7 x 0.4

在此处输入图片描述

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{decorations.pathmorphing, patterns,decorations.markings,shadings,decorations.shapes}
    \begin{document}
    \tikzset{
            %line width=1.2pt,<-- modif
            pics/piczigzag/.style={
                            code={
                                    \draw [dashed,thick](0,0)-| (1,1.5);%<-- added
                                    \draw (3,1.5)--(1,1.5)--(1,2.2)--(3,2.2)--cycle;
                                    \draw  (1.1,2.4)--(2.9,2.3);
                                    \draw  (1.2,2.9)--(2.8,2.8);
                                    \draw  (1.24,3.4)--(2.74,3.3);
                                    \draw  (1.3,3.9)--(2.68,3.8);
                                    \draw  (1.37,4.4)--(2.62,4.3);
                                    \draw  (1.43,4.9)--(2.54,4.8);
                                    \draw  (1.5,5.38)--(2.48,5.28);
                                    \draw  (1.56,5.88)--(2.42,5.78);
                                    \draw  (1.64,6.38)--(2.36,6.28);
                                    \draw  (1.7,6.88)--(2.3,6.78);
                                    \draw[line width=1pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (3,2.2)--(2.35,7);
                                    \draw[line width=1pt,decoration = {zigzag,segment length = 5mm, amplitude = 1mm},decorate] (1.65,7)--(1,2.2);
                                    },
                    }
    }
    %  with scale, don't work, Multiplies all coordinates by the given hfactori but not the ndoe th pic, 
    % \begin{tikzpicture}[line width=1.2pt]
    % \pic [red] at (0,0) {piczigzag};
    % \pic[scale=0.4,blue] at (4,0) {piczigzag};
    % \end{tikzpicture}

    \begin{tikzpicture}[line width=1.2pt]
            \draw [help lines] (0,0) grid(10,10);
            \draw [help lines] [step=0.1](2,0) grid(4,1);
            \pic [red] (A) at (0,0) {piczigzag};
            \pic[transform canvas={scale=0.4},blue] at (7,0) {piczigzag};
    \end{tikzpicture}

    \begin{tikzpicture}[line width=1.2pt]
            \draw [help lines] (0,0) grid(10,10);
            \draw [help lines] [step=0.1](2,0) grid(4,1);
            \pic [red,shift={(-1,-1.5)}] (A) at (0,0) {piczigzag};
            \pic[transform canvas={scale=0.4},blue,shift={(-1,-1.5)}] at (7,0) {piczigzag};
    \end{tikzpicture}
    \end{document}

EDIT2:line width=1.2 pt错误位置

相关内容