Graphics, Figures & TablesReference to a nested Node

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
SAKDOSS
Posts: 14
Joined: Thu Feb 21, 2013 5:06 pm

Reference to a nested Node

Post by SAKDOSS »

Hello,

I have a reference to a nested node which is not working as well as expected. Here is an example:

Code: Select all

\begin{tikzpicture}
  \node[draw, ellipse] (e1){
    \begin{tikzpicture}
      \node (n1) {$a$};
    \end{tikzpicture}
  };

  \node[draw, ellipse] (e2) at (2,0){
    \begin{tikzpicture}
      \node (n2) {$b$};
    \end{tikzpicture}
  };

  % Arrow
  \draw[->, >=latex] (n2) to[out=160, in=20] (c1) ;
\end{tikzpicture}
It give me this :
tikZ-nested-node.jpg
tikZ-nested-node.jpg (2.57 KiB) Viewed 6280 times
The arrow should go from b to the ellipse on the left.

I think instead of starting from the real position of b it starts from the position of b relatively to e2.

Is it possible to fix this? (and to keep the nested structure of the ellipses)

Thanks in advance.
Last edited by localghost on Fri Feb 22, 2013 9:19 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Reference to a nested Node

Post by Stefan Kottwitz »

You can fix it by adding the option remember picture to both tikzpicture environments:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[remember picture]
  \node[draw, ellipse] (e1){
    \begin{tikzpicture}
      \node (n1) {$a$};
    \end{tikzpicture}
  };

  \node[draw, ellipse] (e2) at (2,0){
    \begin{tikzpicture}[remember picture]
      \node (n2) {$b$};
    \end{tikzpicture}
  };

  % Arrow
  \draw[->, >=latex] (n2) to[out=160, in=20] (n1) ;
\end{tikzpicture}
\end{document} 
nested-tikz-pictures.png
nested-tikz-pictures.png (2.68 KiB) Viewed 6272 times
By the way, it would be great if you would post compilable code, as I did here. Just a few lines more, but much easier to work on and a reader can simply open it in the writeLaTeX online compiler.

Stefan
LaTeX.org admin
SAKDOSS
Posts: 14
Joined: Thu Feb 21, 2013 5:06 pm

Re: Reference to a nested Node

Post by SAKDOSS »

Excellent thank you !
Post Reply