1

how can I draw an edge between point a (=O) in the first picture and d (=1) in the second picture:

\usepackage {tikz}
\usetikzlibrary {shapes,arrows,positioning}
\begin {tikzpicture} [-latex, node distance= 1cm]

\node [circle, draw] (a)  {0};

\node [circle, draw] (b) [right=of a] {1};

\node[above,font=\large\bfseries] at (current bounding box.north west) {M};

\end {tikzpicture}

\vspace {2cm}
\begin {tikzpicture} [-latex, node distance= 1cm] 

\node [circle, draw] (c)  {0};

\node [circle, draw] (d) [right=of c] {1};

\node [circle, draw] (e)[right=of d] {2};

\node[above,font=\large\bfseries] at (current bounding box.north west) {N};

\end {tikzpicture}

enter image description here Thank you!

0

1 Answer 1

2

You can use the remember picture option to access coordinates from other tikz pictures:

\documentclass{article}

\usepackage {tikz}
\usetikzlibrary {shapes,arrows,positioning}
\begin{document}
\begin {tikzpicture} [remember picture,-latex, node distance= 1cm]

\node [circle, draw] (a)  {0};

\node [circle, draw] (b) [right=of a] {1};

\node[above,font=\large\bfseries] at (current bounding box.north west) {M};

\end {tikzpicture}

\vspace {2cm}
\begin {tikzpicture} [-latex, node distance= 1cm,remember picture] 

\node [circle, draw] (c)  {0};

\node [circle, draw] (d) [right=of c] {1};

\node [circle, draw] (e)[right=of d] {2};

\node[above,font=\large\bfseries] at (current bounding box.north west) {N};

\draw[overlay] (a) -- (d);

\end {tikzpicture}
\end{document}

enter image description here

5
  • what if there was third pic with also a node called say a in it. How does it know which pic it means when writing (a)--(d) ? Since there are two nodes now called a in two different pics. Are node names global then and not localized to each pic?
    – Nasser
    Commented Oct 25, 2023 at 22:34
  • @Nasser Tikz will use the most recent a. Normally they are localized, but remember picture can make them available to other tikz pictures. Commented Oct 25, 2023 at 22:37
  • @Nasser You can play with pastebin.com/RVjj9wEm Commented Oct 25, 2023 at 22:43
  • Thanks. This is good to know. But I think it will confusing to have two different nodes called the same name and the name used globally like this. A better solution for Tikz would have been to be able to name the pic itself. So one can do pic1.a and pic2.a and so on. But I do not think one can give the whole pic a name.
    – Nasser
    Commented Oct 25, 2023 at 22:45
  • @Nasser You can use the name prefix=... option if you want Commented Oct 25, 2023 at 22:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .