# Draw over mutliple subfigures [duplicate]

I currently try to document a project where a lot of image processing goes on. The problem is, that often tiny details are important to show, but also the reference in the bigger picture is required.

What I'd like to archive is something like this:

I have an overview picture in Figure 1a and show a zoomed-in part of the picture in Figure 1b. So far I am able to do this nicely using bounding box. However it would be nice to add an indicator like the dotted red lines to clarify. This is especially important, when there are multiple areas that need a detail-view in one image.

One other thing I need to do is to add rulers over multiple images, like in Figure 2, in the same sense as you would in a graphics-program.

An answer in Drawing on an image with TikZ pointed me to the Visual Overlay Generator which is an nice alternative way to solve case 1.

Update percusse pointed me to the spy-library. With that I found How to create magnified subfigures and corresponding boxes for portions of a large image which has solutions and a lot of nice examples.

• Did you use spy library of TikZ? For example tex.stackexchange.com/questions/57638/… – percusse May 19 '15 at 15:01
• No, haven't heard of it, but looks very promising. Thanks! – Mene May 19 '15 at 15:03
• You probably need tikzmark to draw lines spanning over subfigures. – Symbol 1 May 19 '15 at 16:34

You can use a node around each subfigure and draw lines later

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

\begin{document}
\begin{figure}
\begin{subfigure}[b]{.45\linewidth}
\centering
\tikz[overlay, remember picture] \node[anchor=south, inner sep=0] (model) {\includegraphics[width=\linewidth]{Mycena_interrupta}};
\caption{Model}
\end{subfigure}
\hfill
\begin{subfigure}[b]{.45\linewidth}
\centering
\tikz[overlay, remember picture] \node[anchor=south, inner sep=0] (replica) {\includegraphics[width=\linewidth]{Mycena_interrupta}};
\caption{Replica}
\end{subfigure}
\caption{A figure}
\begin{tikzpicture}[overlay, remember picture]
\draw[red, thick] ([shift={(-3mm, 8mm)}]model.west)--([shift={(3mm, 8mm)}]replica.east);
\draw[red, thick] ([shift={(-3mm, -8mm)}]model.west)--([shift={(3mm, -8mm)}]replica.east);
\draw[red, blue] ([shift={(-3mm, -5mm)}]model.west)--([shift={(3mm, -5mm)}]replica.east);
\end{tikzpicture}
\end{figure}
\end{document}


Update: (2nd version)

I'll leave previous solution because it has been already accepted but I think that not using overlay in subfigure nodes simplifies the code, and it's more correct than the original one:

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

\begin{document}
\begin{figure}
\begin{subfigure}[b]{.45\linewidth}
\centering
\tikz[remember picture] \node[inner sep=0] (model) {\includegraphics[width=\linewidth]{Mycena_interrupta}};
\caption{Model}
\end{subfigure}
\hfill
\begin{subfigure}[b]{.45\linewidth}
\centering
\tikz[remember picture] \node[inner sep=0] (replica) {\includegraphics[width=\linewidth]{Mycena_interrupta}};
\caption{Replica}
\end{subfigure}
\caption{A figure}
\begin{tikzpicture}[overlay, remember picture]
\draw[red, thick] ([shift={(-3mm, 8mm)}]model.west)--([shift={(3mm, 8mm)}]replica.east);
\draw[red, thick] ([shift={(-3mm, -8mm)}]model.west)--([shift={(3mm, -8mm)}]replica.east);
\draw[red, blue] ([shift={(-3mm, -5mm)}]model.west)--([shift={(3mm, -5mm)}]replica.east);
\end{tikzpicture}
\end{figure}
\end{document}