突出显示第二个子图中已放大的子图区域

突出显示第二个子图中已放大的子图区域

我正在使用\subcaption包来显示两幅图像,其中第二幅图像是第一幅图像的放大版本。我使用以下代码来显示图像。

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
    \centering
    \begin{subfigure}{0.8\textwidth}
        \includegraphics[width=\linewidth,height=3.7cm]{a.png}
        \caption{All components} \label{fig:a}
    \end{subfigure}
    \par \bigskip \bigskip \bigskip \bigskip
    \begin{subfigure}{0.8\textwidth}
        \includegraphics[width=\linewidth,height=3.7cm]{b.png}
        \caption{Zoom in view of a single component} \label{fig:b}
    \end{subfigure}
    \caption{Test} \label{fig:test}
\end{figure}

\end{document}

我得到下图作为输出。

在此处输入图片描述

但是,我想突出显示第一张图中已在第二张图中放大的部分。类似这样。图像 (a) 的标题也可以显示在线上。

在此处输入图片描述

答案1

使用行上方的标题进行编辑

脚步:

  1. 找到需要连接的点
  2. 这些点处的节点
  3. 与覆盖 tikzpicture 的连接(线路或其他)。
  4. 找到标题的要点并注释掉真正的标题。
  5. 添加\captionof关于特定要点的小页面。

代码:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup[subfigure]{labelsep=space,labelformat = parens}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

Text before


\begin{figure}[htp]
    \centering
\begin{subfigure}{0.8\textwidth}
\begin{tikzpicture}[remember picture]
\node at (0,0){\includegraphics[width=\linewidth,height=3.7cm]{example-image-a}};
%\fill[red] (-2.6,-1.85) circle (3pt); % <-First step find points using circles 
%\fill[red] (-1.8,-1.85) circle (3pt); % <-First step
\node(A) at (-2.6,-1.85){}; % Second step: nodes on the points found by first step
\node(B) at (-1.8,-1.85){}; % Second step
\node(E) at (0,-2.6){}; %Fourth step find positions for captions
\end{tikzpicture}
%\caption{All components} \label{fig:a} %Commented on fourth step
\end{subfigure}
\par \bigskip \bigskip \bigskip \bigskip
\begin{subfigure}{0.8\textwidth}
\begin{tikzpicture}[remember picture]
\node at (0,0) {\includegraphics[width=\linewidth,height=3.7cm]{example-image-b}};
%\fill[red] (-4.8,1.85) circle (3pt); % <-First step find points using circles 
%\fill[red] (4.8,1.85) circle (3pt); % <-First step
\node(C) at (-4.8,1.85) {}; % Second step: nodes on the points found by first step
\node(D) at (4.8,1.85) {}; % Second step
\node(F) at (0,-2.6){}; %Fourth step
\end{tikzpicture}
%\caption{Zoom in view of a single component} \label{fig:b} %Commented on fourth step
\end{subfigure}
\caption{Test} \label{fig:test}
\end{figure}

\begin{tikzpicture}[remember picture,overlay] %Third step: connect points
   \draw[-,blue,thick] (A.center)--(C.center); %Third step
   \draw[-,blue, thick] (B.center)--(D.center); %Third step
   \node at (E) {\begin{minipage}{0.8\textwidth} %Fifth Step
\captionof{subfigure}{All components}\label{fig:a}
\end{minipage}
};
   \node at (F) {\begin{minipage}{0.8\textwidth} %Fifth step
\captionof{subfigure}{Zoom in view of a single component}\label{fig:b}
\end{minipage}
};
\end{tikzpicture}

Text continues here

\end{document}

结果如下所示,但标题位于行上方

旧答案 这是一个 tikz 解决方案:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
Text before
\begin{figure}[htp]
    \centering
\begin{subfigure}{0.8\textwidth}
\begin{tikzpicture}[remember picture]
\node at (0,0){\includegraphics[width=\linewidth,height=3.7cm]{example-image-a}};
%\fill[red] (-2.6,-1.85) circle (3pt); % <-First step find points using circles 
%\fill[red] (-1.8,-1.85) circle (3pt); % <-First step
\node(A) at (-2.6,-1.85){}; % Second step: nodes on the points found by first step
\node(B) at (-1.8,-1.85){}; % Second step
\end{tikzpicture}
\caption{All components} \label{fig:a}
\end{subfigure}
\par \bigskip \bigskip \bigskip \bigskip
\begin{subfigure}{0.8\textwidth}
\begin{tikzpicture}[remember picture]
\node at (0,0) {\includegraphics[width=\linewidth,height=3.7cm]{example-image-b}};
%\fill[red] (-4.8,1.85) circle (3pt); % <-First step find points using circles 
%\fill[red] (4.8,1.85) circle (3pt); % <-First step
\node(C) at (-4.8,1.85) {}; % Second step: nodes on the points found by first step
\node(D) at (4.8,1.85) {}; % Second step
\end{tikzpicture}
        \caption{Zoom in view of a single component} \label{fig:b}
    \end{subfigure}
    \caption{Test} \label{fig:test}
\end{figure}
\begin{tikzpicture}[remember picture,overlay] %Third step: connect points
   \draw[-,blue,thick] (A.center)--(C.center); %Third step
   \draw[-,blue, thick] (B.center)--(D.center); %Third step
\end{tikzpicture}
Text continues here
\end{document}

我分 3 步注释了代码:

  1. 找到需要连接的点
  2. 这些点处的节点
  3. 与覆盖 tikzpicture 的连接(线路或其他)。

输出:

在此处输入图片描述

相关内容