問題

問題

問題

私はいくつかのコードをコピーしましたここそしてここそして、自分の作品に最適な部分を組み合わせました。なぜ長方形の座標は画像のパーセンテージで表されているのに、スパイグラスの座標はそうではないのか疑問に思います。

動作例

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}

\begin{tikzpicture}[spy using outlines={circle,red,magnification=5,size=1.5cm, connect spies}]
\node [anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=10cm]{tux}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
    \draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
    \spy on (4.5,7) in node [] at (3,5);
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
    \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
    \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
\end{document}

2度目の試み

この例では、パラメータspy using outlines={circle,red,magnification=5,size=1.5cm, connect spies}内に を入れようとしました\begin{scope}が、うまくいきませんでした。画像が間違った場所で拡大表示されます。私のアイデアは pgfmanual (68 Spy Library: Magnifying Parts of Pictures、v.3.0.0 の p.746) から得たものですが、残念ながらうまくいきませんでした。

\documentclass{standalone} 
\usepackage{tikz} 
\usetikzlibrary{spy} 
\begin{document}

\begin{tikzpicture}[]
\node [anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=10cm]{tux}};
\begin{scope}[x={(image.south east)},y={(image.north west)},spy using outlines={circle,red,magnification=5,size=1.5cm, connect spies}]
    \draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
    \spy on (4.5,7) in node [] at (3,5);
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
    \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
    \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
\end{document}

答え1

\spyオプションのスコープ内の座標系を使用しますspy using outlines。画像を監視するために特別な座標系を使用するには、名前付き座標を定義します。

ここに画像の説明を入力してください

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}

\begin{tikzpicture}[spy using outlines={circle,red,magnification=3,size=2.5cm, connect spies}]
\node [anchor=south west,inner sep=0] (image)
at (0,0) {\includegraphics[height=10cm]{example-image}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
    \draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
    \coordinate (pos spy) at (.2,.2);
    \coordinate (center) at (.5,.5);
    \spy on (center) in node [] at (pos spy);
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
    \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
    \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
\end{document}

関連情報