Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw a small rectangle within a tikz picture, then zoom it out somewhere. I skim through the PGF manual but I couldn't find a way to put the logic together. So far I've just drawn the automaton diagram, I had to hack the blue rectangle with "paint" though :(. Anyone could help me out with this? Thank you.

enter image description here

Minimal Working Example

\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}
share|improve this question
    
You might also like tex.stackexchange.com/questions/25414/… –  cmhughes Sep 24 '11 at 14:33
    
@cmhughes: Thanks a lot ;)! –  Chan Oct 10 '11 at 9:46
add comment

1 Answer

up vote 24 down vote accepted

The spy TikZ-library was created exactly for this. Here an example. See the PGF/TikZ manual in section 49 Spy Library: Magnifying Parts of Pictures, page 462 for more details.

\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}

Result

share|improve this answer
    
Many thanks for a quick and precise answer ;). The picture looks awesome by the way. –  Chan Sep 24 '11 at 7:33
1  
I just wanted to add here that this code does not work when compiled with XeLaTeX (in case anybody is hitting their head on a desk). The picture shows up fine, but the spy zoom is blank. A solution has not yet been provided: tex.stackexchange.com/questions/33260/… –  macmadness86 Nov 17 '13 at 20:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.