使用 tikz 放大图片

使用 tikz 放大图片

在此处输入图片描述我有一个将自动机表示为黑框(图的左侧部分)的图,我想在下一张投影仪幻灯片上显示相同的图,但自动机 B4 的放大倍数(如图的右侧所示)。我看过几篇关于放大的帖子,但没有找到我想要的东西。这是我的起始代码:

\begin{document}
\documentclass{article} 
\tikzset{
  ncbar angle/.initial=90,
  ncbar/.style={
    to path=(\tikztostart)
    -- ($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)
    -- ($(\tikztotarget)!($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztostart)$)
    -- (\tikztotarget)
  },
  ncbar/.default=0.5cm,
}
\begin{figure}[h]
  \center
\begin{tikzpicture}[->,node distance=1.3cm,>=stealth',bend angle=20,auto,
  place/.style={circle,thick,draw=blue!75,fill=blue!20,minimum size=10mm},
  red place/.style={place,draw=red!75,fill=red!20}
  every label/.style={red},
  every node/.style={scale=.6},
  dots/.style={fill=black,circle,inner sep=2pt},
  triangle/.style={fill=black,regular polygon,regular polygon sides=3,minimum size=10pt,inner sep=0pt,}]

  \node (rec2) at (0,0) [draw, thick,minimum width=2cm,minimum height=2cm]{$B_{2}$};
  \node (rec1) [draw, left=of rec2,xshift=2cm,thick,minimum width=2cm,minimum height=2cm,align=center]{$B_{1}$};
  \node (rec3) [draw, right=of rec2,xshift=-2cm,thick,minimum width=2cm,minimum height=2cm,align=center]{$B_{3}$};
  \node (rec4) [draw, right=of rec3,xshift=-2cm,thick,minimum width=2cm,minimum height=2cm,align=center]{$B_{4}$};


  \node [dots] (p1) at ($(rec2.north west)!0.5!(rec2.north east)$) {};
  \node [dots] (p2) at ($(rec2.north west)!0.5!(rec2.north east)$) {};
  \node [dots] (q1) at ($(rec1.north west)!0.5!(rec1.north east)$) {};
  \node [dots] (q2) at ($(rec3.north west)!0.3!(rec3.north east)$) {};
  \node [dots] (r1) at ($(rec3.north west)!0.7!(rec3.north east)$) {};
  \node [dots] (r2) at ($(rec4.north west)!0.3!(rec4.north east)$) {};



  \draw [-] (q1) to[ncbar] (p1) node[xshift=-8mm,yshift=1cm]{$\alpha_1$};
  \draw [-] (q2) to[ncbar=-5mm] (p2) node[xshift=8mm,yshift=1cm]{$\alpha_2$};
  \draw [-] (r2) to[ncbar=-5mm] (r1) node[xshift=8mm,yshift=1cm]{$\alpha_3$};



\end{tikzpicture}
\end{figure}
\end{document}

答案1

您可以使用 TikZspy库。

输出

在此处输入图片描述

代码

\documentclass{article} 
\usepackage{tikz}

\usetikzlibrary{calc,positioning,spy,arrows}

\tikzset{
  ncbar angle/.initial=90,
  ncbar/.style={
    to path=(\tikztostart)
    -- ($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)
    -- ($(\tikztotarget)!($(\tikztostart)!#1!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztotarget)$)!\pgfkeysvalueof{/tikz/ncbar angle}:(\tikztostart)$)
    -- (\tikztotarget)
  },
  ncbar/.default=0.5cm,
}
\begin{document}
\begin{figure}[h]
  \center
\begin{tikzpicture}[->,node distance=1.3cm,>=stealth',bend angle=20,auto,
  place/.style={circle,thick,draw=blue!75,fill=blue!20,minimum size=10mm},
  red place/.style={place,draw=red!75,fill=red!20}
  every label/.style={red},
  every node/.style={scale=.6},
  dots/.style={fill=black,circle,inner sep=2pt},
  triangle/.style={fill=black,regular polygon,regular polygon sides=3,minimum size=10pt,inner sep=0pt,},
  spy using outlines={circle, magnification=2.5, size=8cm},]

  \node (rec2) at (0,0) [draw, thick,minimum width=2cm,minimum height=2cm]{$B_{2}$};
  \node (rec1) [draw, left=of rec2,xshift=2cm,thick,minimum width=2cm,minimum height=2cm,align=center]{$B_{1}$};
  \node (rec3) [draw, right=of rec2,xshift=-2cm,thick,minimum width=2cm,minimum height=2cm,align=center]{$B_{3}$};
  \node (rec4) [draw, right=of rec3,xshift=-2cm,thick,minimum width=2cm,minimum height=2cm,align=center]{$B_{4}$};


  \node [dots] (p1) at ($(rec2.north west)!0.5!(rec2.north east)$) {};
  \node [dots] (p2) at ($(rec2.north west)!0.5!(rec2.north east)$) {};
  \node [dots] (q1) at ($(rec1.north west)!0.5!(rec1.north east)$) {};
  \node [dots] (q2) at ($(rec3.north west)!0.3!(rec3.north east)$) {};
  \node [dots] (r1) at ($(rec3.north west)!0.7!(rec3.north east)$) {};
  \node [dots] (r2) at ($(rec4.north west)!0.3!(rec4.north east)$) {};



  \draw [-] (q1) to[ncbar] (p1) node[xshift=-8mm,yshift=1cm]{$\alpha_1$};
  \draw [-] (q2) to[ncbar=-5mm] (p2) node[xshift=8mm,yshift=1cm]{$\alpha_2$};
  \draw [-] (r2) to[ncbar=-5mm] (r1) node[xshift=8mm,yshift=1cm]{$\alpha_3$};

\spy on ($(rec1)!.5!(rec2)$) in node[line width=2mm,fill=cyan!5] (s) at ($(rec1)!.5!(rec2)$);
\end{tikzpicture}
\end{figure}
\end{document}

相关内容