我想放大 LaTeX 中的图像,使原始图像在缩放部分内可见。如果我使用 spy 库,则缩放部分始终位于顶部。我找不到如何将放大部分移到主图像下方。请参阅以下最小示例。我希望左侧图像(在输出 PDF 中)位于右侧图像(缩放图像)的顶部。换句话说,我希望主图像作为插图位于缩放部分的右下角,并用红色矩形显示哪个区域被缩放。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}
\begin{tikzpicture}
[spy using outlines={rectangle,red,magnification=7,size= 8 cm}]
\node {\includegraphics[width=.3\linewidth]{example-image}};
\spy on (-1,0) in node at (4.5,3);
\end{tikzpicture}
\end{document}
答案1
更新:Paul Gaborit 提供了更简单的解决方案。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spy,backgrounds}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{tikzpicture}[spy using outlines={rectangle,red,magnification=7,size= 8 cm}]
\node {\includegraphics[width=.3\linewidth]{example-image-a}};
\spy[on background layer,
spy connection path={ \draw (tikzspyonnode) -- (tikzspyinnode);
\begin{pgfonlayer}{foreground}
\draw[red] (tikzspyonnode.south west) rectangle (tikzspyonnode.north east);
\end{pgfonlayer}}] on (-1,0) in node at (4.5,3);
\end{tikzpicture}
\end{document}
**老旧且糟糕的解决方案**:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spy,backgrounds}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\begin{document}
\begin{tikzpicture}
\begin{scope}[spy using outlines={rectangle,red,magnification=7,size= 8 cm}]
\node (x) {\includegraphics[width=.3\linewidth]{example-image}};
\spy[spy connection path={\draw (tikzspyonnode) -- (tikzspyinnode);
\path coordinate (bl) at (tikzspyonnode.south west);
\path coordinate (tr) at (tikzspyonnode.north east);}] on (-1,0) in node at (4.5,3);
\end{scope}
\begin{pgfonlayer}{foreground}
\node (y) at (x) {\includegraphics[width=.3\linewidth]{example-image}};
\draw[red] (bl) rectangle (tr);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
我为什么要发布所有这些解决方案?只是因为“更明显”的解决方案似乎不起作用。例如,
\begin{tikzpicture}[spy using outlines={rectangle,red,magnification=7,size= 8 cm}]
\node (x) {\includegraphics[width=.3\linewidth]{example-image}};
\begin{pgfonlayer}{background}
\spy on (-1,0) in node at (4.5,3);
\end{pgfonlayer}
\end{tikzpicture}
产量
即放大的图片是不是在背景上,更令人惊讶的是
\begin{tikzpicture}[spy using outlines={rectangle,red,magnification=7,size= 8 cm}]
\begin{pgfonlayer}{foreground}
\node (x) {\includegraphics[width=.3\linewidth]{example-image}};
\end{pgfonlayer}
\spy on (-1,0) in node at (4.5,3);
\end{tikzpicture}
给出