I want to magnify part of a picture with the TikZ spy library; however, with a scope for using relative coordinates like in #9561 Drawing on an image with TikZ. Provided I'm using the image tux.png - consider this MWE:
\documentclass[%
12pt,
journal,
onecolumn,
twoside,
draftcls,
letterpaper,
]{IEEEtran}
% wget http://i.stack.imgur.com/aVGcn.png -O tux.png
\usepackage[nopar]{lipsum}
\usepackage{xstring}
% https://tex.stackexchange.com/a/26808/2595
\makeatletter
\def\unpacklipsum#1#2#3{%
\count@=#1\relax
\advance\count@\m@ne
\def#3{}%
\loop\ifnum\count@<#2\relax
\advance\count@\@ne
\edef#3{#3\csname lipsum@\romannumeral\count@\endcsname}%
\repeat}
\makeatother
% https://tex.stackexchange.com/a/168754/2595
\def\loremnchars[#1]#2{%
\unpacklipsum{#1}{#1}{\myunpacked}%
\StrMid{\myunpacked}{1}{#2}% same as \StrLeft{\myunpacked}{#2}
}
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{spy}
\begin{document}
\begin{center}
\begin{tikzpicture}[
spy using outlines={%
draw=red,
ellipse,
red,
magnification=2,
connect spies
}
]
\node [draw=black, anchor=south west, inner sep=0pt] (myimg) at (0,0) {
\includegraphics[width=0.9\textwidth]{tux.png}
};
\begin{scope}[
x={(myimg.south east)},y={(myimg.north west)},
spy using outlines={%
draw=red,
ellipse,
red,
magnification=2,
connect spies
}
]
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\node[
draw=red,ellipse,line width=1pt,minimum width=0.9cm,minimum height=5.25cm
]
at (0.53,0.7) {};
\spy[
draw=red,ellipse,line width=1pt,minimum width=0.9cm,minimum height=5.25cm
]
on (0.53,0.7) in node [left] at (0.8,0.825);
\end{scope}
\end{tikzpicture}
\captionof{figure}[justmy]{Just my image; \loremnchars[5]{255} ...}
\label{fig:test}
\end{center}
\end{document}
It produces this image:
The first \node ... at (0.53,0.7)
is merely to indicate the area that I want to be spied on. Two problems are visible:
- The same settings as used for that
\node
, when applied to a\spy
, result with an ellipse smaller than the originally requested one - Apparently, since a scope is used, the
\spy
doesn't "see" any graphics (more precisely, image pixels) "below", so it seemingly only zooms in the grid.
Can I use this kind of a setup of \includegraphics
and scope
inside a tikzpicture
, but still obtain a proper \spy
, expressed in relative coordinates - and if yes, how?