TikZ 库spy

TikZ 库spy

我想放大一个图形,例如下面的矩形:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}
\begin{tikzpicture}[
       >=latex,
       font=\sffamily,
    open circle/.style={
        circle, inner sep=0pt,
        thick,draw=black,
        fill = white,
    },
    junction/.style={open circle, minimum size=0.5mm,fill=black, node distance=5mm}       
       ]

\node[junction, label={left:A}](A) at (0,0){};
\node[junction, label={left:}](B) at (5,5){};
\node[junction, label={left:}](C) at (5.05,4.95){};
\node[junction, label={right:}](D) at (4.95,5.05){};
\draw[rotate around={-45:(5,5)}] (5,5) ellipse (0.09 and 0.05);

\draw[->] (A) -- (B);
\draw[->] (A) -- (C);
\draw[->] (A) -- (D);

\draw [red] (4.7,4.8) rectangle (5.3,5.2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

我该怎么做?我试过了\begin{scope}[scale=10],但它只会使图形变大。

答案1

TikZ 库spy

该库spy使用相同的因子放大所有元素:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,spy}
\begin{document}
\begin{tikzpicture}[
       >=latex,
       font=\sffamily,
    open circle/.style={
        circle, inner sep=0pt,
        thick,draw=black,
        fill = white,
    },
    junction/.style={
      open circle, minimum size=0.5mm,fill=black, node distance=5mm
    },
    spy using outlines={
      rectangle,
      magnification=6,
      width=2.25cm,
      height=2.05cm,
      connect spies,
    },
]

\node[junction, label={left:A}](A) at (0,0){};
\node[junction, label={left:}](B) at (5,5){};
\node[junction, label={left:}](C) at (5.05,4.95){};
\node[junction, label={right:}](D) at (4.95,5.05){};
\draw[rotate around={-45:(5,5)}] (5,5) ellipse (0.09 and 0.05);

\draw[->] (A) -- (B);
\draw[->] (A) -- (C);
\draw[->] (A) -- (D);

% \draw [red] (4.7,4.8) rectangle (5.3,5.2);
\spy[red] on (4.94, 4.93)
  in node[below right] at (current bounding box.north west);
\end{tikzpicture}
\end{document}

结果

复制绘图scale

如果某些元素(如文本和箭头)不应该缩放,则可以复制整个图形,剪切感兴趣的区域并移动到显示区域:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, calc, fit}
\begin{document}
\begin{tikzpicture}[
       >=latex,
       font=\sffamily,
    open circle/.style={
        circle, inner sep=0pt,
        thick,draw=black,
        fill = white,
    },
    junction/.style={
      open circle, minimum size=0.5mm,fill=black, node distance=5mm
    },
]

\def\Stuff{%
  \node[junction, label={left:A}](A) at (0,0){};
  \node[junction, label={left:}](B) at (5,5){};
  \node[junction, label={left:}](C) at (5.05,4.95){};
  \node[junction, label={right:}](D) at (4.95,5.05){};
  \draw[rotate around={-45:(5,5)}] (5,5) ellipse (0.09 and 0.05);


  \draw[->] (A) -- (B);
  \draw[->] (A) -- (C);
  \draw[->] (A) -- (D);
}
\Stuff

\def\LL{(4.68, 4.83)}
\def\UR{(5.2, 5.12)}
\node[draw=red, inner sep=0pt, fit=\LL\UR] (ViewPortA) {};

\begin{scope}[scale=6, xshift=-4.7cm, yshift=-4.27cm]
  \node[draw=red, inner sep=0pt, fit=\LL\UR] (ViewPortB) {};
  \clip (ViewPortB.south west) rectangle (ViewPortB.north east);
  \Stuff
\end{scope}
\draw[red] (ViewPortA.west) -- (ViewPortB.east);

\end{tikzpicture}
\end{document}

结果量表

答案2

这正是我一直在寻找的东西,有没有办法用图书馆spy或其他东西更轻松地做到这一点?(为什么不起作用\coordinate?)

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}
\begin{tikzpicture}[
       >=latex,
       font=\sffamily,
    open circle/.style={
        circle, inner sep=0pt,
        thick,draw=black,
        fill = white,
    },
    junction/.style={open circle, minimum size=0.5mm,fill=black, node distance=5mm}       
       ]

\def\true{1}       
\def\false{0}       
\coordinate (R1) at (4.85,4.9);
\coordinate (R2) at (5.15,5.1);
\foreach \zoom in {\false,\true}{       
\if \zoom\true
\begin{scope}[shift=({2.8,5.2}),scale=10, shift={(-5.15,-5.1)}]
\clip(4.85,4.9) rectangle (5.15,5.1);   % (R1) rectangle (R2) doesn't work here... why?
\fi

\node[junction, label={left:A}](A) at (0,0){};
\node[junction, label={left:\if\zoom\true B\fi}](B) at (5,5){};
\node[junction, label={left:\if\zoom\true C\fi}](C) at (5.05,4.95){};
\node[junction, label={right:\if\zoom\true D\fi}](D) at (4.95,5.05){};
\draw[rotate around={-45:(5,5)}] (5,5) ellipse (0.09 and 0.05);

\draw[->] (A) -- (B);
\draw[->] (A) -- (C);
\draw[->] (A) -- (D);

\draw [red] (4.85,4.9) rectangle (5.15,5.1); % (R1) rectangle (R2) doesn't work here... why?
\if \zoom\true
\end{scope}
\fi
}
\draw[dashed, red] (2.8, 5.0) -- (4.85,5.0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容