使用tikz模块,将图像进行局部放大,多图排版

使用tikz模块将图像的局部放大,并放在该图像的附近。让后将该图像及其放大后的局部图像当作一个子图(使用subfigure“包裹”住每一个tikzpicture),将多个子图进行排列展示(使用resizebox“包裹”住多个子图,使其并排在一行)。

示例代码如下

\documentclass[fontset=windows]{ctexart}
\usepackage{ctex}
\usepackage{tikz}
\usepackage{float}
\usepackage{subfigure}

\usetikzlibrary{decorations.fractals,spy}

\begin{document}

\begin{figure}[H]
\centering
\resizebox{\linewidth}{!}{
\subfigure[1]{
% rectangle 表示使用矩形框出所选部分
% magnification 表示放大倍数
% size 表示局部图片放大后的大小
\begin{tikzpicture}[spy using outlines={rectangle, magnification=5, size=19pt}]
% 插入本地图片。 这里的height(或width) 与上述参数 magnification size 的数值可以自行调整。
% at (0,0) anchor=south west:图像的左下角位置为坐标 (0,0)
\node[anchor=south west, inner sep=0] at (0,0){\includegraphics[height=40pt]{kodim1.png}};
% blue 表示框的颜色为蓝色
% on (1,1)表示图像中局部图像的位置(应该是中心点?)
% at (2.2 30.5pt) 将局部图像放在哪个位置
% 上述 on 和 at 的位置尽量和插入图像的height(width)保持量纲一致(方便调整)
\spy [blue] on (1,1) in node [right] at (2.2,30.5pt);
\spy [red] on (1.6,0.3) in node [right] at (2.2,10pt);
\end{tikzpicture}}

\subfigure[2]{
\begin{tikzpicture}[spy using outlines={rectangle, magnification=5, size=19pt}]
\node[anchor=south west, inner sep=0] at (0,0){\includegraphics[height=40pt]{kodim2.png}};
\spy [blue] on (1,1) in node [right] at (2.3,30.5pt);
\spy [red] on (1.6,0.3) in node [right] at (2.3,10pt);
\end{tikzpicture}}
}

\resizebox{\linewidth}{!}{
\subfigure[3]{
\begin{tikzpicture}[spy using outlines={rectangle, magnification=5, size=19pt}]
\node[anchor=south west, inner sep=0] at (0,0){\includegraphics[height=40pt]{kodim3.png}};
\spy [blue] on (1,1) in node [right] at (2.3,30.5pt);
\spy [red] on (1.6,0.3) in node [right] at (2.3,10pt);
\end{tikzpicture}}

\subfigure[4]{
\begin{tikzpicture}[spy using outlines={rectangle, magnification=5, size=19pt}]
\node[anchor=south west, inner sep=0] at (0,0){\includegraphics[height=40pt]{kodim22.png}};
\spy [blue] on (1,1) in node [right] at (2.2,30.5pt);
\spy [red] on (1.6,0.3) in node [right] at (2.2,10pt);
\end{tikzpicture}}
}
\caption{tikzpicture作为子图嵌套在figure中}
\end{figure}
\end{document}

编译后的样子如图

posted @ 2022-09-03 13:53  DifDay哒哒哒  阅读(832)  评论(0编辑  收藏  举报