4

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): :)

enter image description here

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

1 Answer 1

5

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}

enter image description here

4
  • 2
    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
  • 1
    Yes... also the centering but this is out of subject...
    – koleygr
    Jan 16 at 14:06
  • 1
    Thank you very much! I thought remember picture is only for those tikzpicture that should be remembered. :) Jan 17 at 12:17
  • 1
    Me too some time ago @MichaelDorner
    – koleygr
    Jan 17 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.