Draw across two tikzpicture in subfigures

I would like to draw a connection between two tikzpicture, each in a subfigure - in the following MWE, between the nodes n1 and n3. I think my code makes sense:

\documentclass[a4paper, 12pt]{article}

\usepackage{subcaption}
\usepackage{tikz}

\usetikzlibrary{automata, positioning, arrows, decorations.pathreplacing, calc, chains, shapes.misc}

\begin{document}

some text some more text

\begin{figure*}

%left subfigure
\begin{subfigure}[t]{.45\textwidth}
\begin{tikzpicture}[remember picture]
\node[draw, red] (n1) at (0,0) {};
\end{tikzpicture}
\caption{Caption A}
\end{subfigure}
%
\hfill
% right subfigure
\begin{subfigure}[t]{.45\textwidth}
\begin{tikzpicture}[remember picture]
\node[draw, red] (n2) at (0,0) {};
\node[draw, red] (n3) at (1,1) {};
\end{tikzpicture}
\caption{Caption B}
\end{subfigure}

\begin{tikzpicture}[overlay]
\draw[blue] (n1) -- (n2);
\end{tikzpicture}

\caption{Some caption for A and B.}
\end{figure*}

\end{document}


However, the results tells I am wrong (please note the blue line on the very top): :)

But I don't know what I am doing wrong.

Try like this:

\documentclass[a4paper, 12pt]{article}

\usepackage{subcaption}
\usepackage{tikz}

\usetikzlibrary{automata, positioning, arrows, decorations.pathreplacing, calc, chains, shapes.misc}

\begin{document}

some text some more text

\begin{figure*}

%left subfigure
\begin{subfigure}[t]{.45\textwidth}
\centering
\begin{tikzpicture}[remember picture]
\node[draw, red] (n1) at (0,0) {};
\end{tikzpicture}
\caption{Caption A}
\end{subfigure}
%
\hfill
% right subfigure
\begin{subfigure}[t]{.45\textwidth}
\centering
\begin{tikzpicture}[remember picture]
\node[draw, red] (n2) at (0,0) {};
\node[draw, red] (n3) at (1,1) {};
\end{tikzpicture}
\caption{Caption B}
\end{subfigure}
\begin{tikzpicture}[overlay, remember picture]
\draw[blue] (n1) -- (n2);
\end{tikzpicture}
\caption{Some caption for A and B.}
\end{figure*}

\end{document}


• Thank you very much! When I haven't missed a thing it is just the remember picture was missing for the last tikzpicture, wasn't it? Jan 16 at 13:57
• Yes... also the centering but this is out of subject... Jan 16 at 14:06
• Thank you very much! I thought remember picture is only for those tikzpicture that should be remembered. :) Jan 17 at 12:17
• Me too some time ago @MichaelDorner Jan 17 at 12:38