如何缩放 TiKZ 图片的局部?

如何缩放 TiKZ 图片的局部?

我想在 tikz 图片中绘制一个小矩形,然后将其缩小到某个位置。我浏览了 PGF 手册,但找不到将逻辑组合在一起的方法。到目前为止,我刚刚绘制了自动机图,但我不得不用“paint”破解蓝色矩形 :(。有人可以帮我吗?谢谢。

在此处输入图片描述

最小工作示例

\documentclass[10pt,letterpaper]{article}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry} 
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}

\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,backgrounds,petri,positioning}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.fractals}
\usetikzlibrary{decorations.footprints}
\usetikzlibrary{shadows}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[shorten >=1pt, node distance=3cm, auto, on grid, initial text=,font=\small,>=stealth',
            every state/.style={minimum size=7mm,draw=black!50,very thick,fill=red!50}]
        \node[state,initial]        (S)                 {S};
        \node[state]                (A) [right=of S]    {A};
        \node[state]                (B) [below=of S]    {B};
        \node[state,accepting]      (C) [right=of B]    {C};
        \path[->]
        (S) edge[bend right]    node{a} (A)
        (S) edge[bend right]    node[xshift=-4mm]{$\lambda$} (B)
        (A) edge[bend right]    node[yshift=5mm]{a,b} (S)
        (A) edge[]              node{$\lambda$} (C)
        (A) edge[]              node[yshift=7mm]{b} (B)
        (B) edge[bend left]     node{b, $\lambda$} (C)
        (B) edge[bend right]    node[xshift=4mm]{a} (S)
        (C) edge[bend left]     node{a,b} (B)

        ; 
        \end{tikzpicture}
    \end{center}
\end{document}

答案1

spy库就是为此而创建的。这里有一个例子。请参阅第 49 节中的 PGF/TikZ 手册间谍图书馆:放大图片的部分内容,第 462 页,了解更多详情。

\documentclass[10pt,letterpaper]{article}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry} 
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}

\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,automata,backgrounds,petri,positioning}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.fractals}
\usetikzlibrary{decorations.footprints}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}
\usetikzlibrary{spy}

\begin{document}
    \begin{center}
        \begin{tikzpicture}[shorten >=1pt, node distance=3cm, auto, on grid, initial text=,font=\small,>=stealth',
            every state/.style={minimum size=7mm,draw=black!50,very thick,fill=red!50},spy using outlines]
        \node[state,initial]        (S)                 {S};
        \node[state]                (A) [right=of S]    {A};
        \node[state]                (B) [below=of S]    {B};
        \node[state,accepting]      (C) [right=of B]    {C};
        \path[->]
        (S) edge[bend right]    node{a} (A)
        (S) edge[bend right]    node[xshift=-4mm]{$\lambda$} (B)
        (A) edge[bend right]    node[yshift=5mm]{a,b} (S)
        (A) edge[]              node{$\lambda$} (C)
        (A) edge[]              node[yshift=7mm]{b} (B)
        (B) edge[bend left]     node{b, $\lambda$} (C)
        (B) edge[bend right]    node[xshift=4mm]{a} (S)
        (C) edge[bend left]     node{a,b} (B)

        ; 
        \spy [blue,draw,height=5cm,width=10cm,magnification=2,connect spies] on ($(B)!.5!(C)$) in node at ($(B)!.5!(C) + (0,-5) $);
        \end{tikzpicture}
    \end{center}
\end{document}

结果

相关内容