3

Got the following from a student. The last line is trying to access the nodes inside of nodes A and B, but it doesn't do so. Can this approach succeed?

\begin{tikzpicture}[remember picture,
  inner/.style={circle,draw=black!50,fill=white!20,thick,inner sep=3pt},
  outer/.style={draw=black,fill=black!20,thick,inner sep=10pt}
  ]
  \node[outer,draw=black] (A) {
    \begin{tikzpicture}
      \node[inner, state] (a) {$a$};
      \node[inner, state] (b) [below =of a] {$b$};
      \node[inner, state] (c) [below =of b] {$c$};
      \node[inner, state] (d) [below =of c] {$d$};
      \node[inner, state] (e) [below =of d] {$e$};
    \end{tikzpicture}
  };
  \node[outer,draw=black,right=of A] (B) {
    \begin{tikzpicture}
      \node[inner, state] (f) {$f$};
      \node[inner, state] (g) [below =of f] {$g$};
      \node[inner, state] (h) [below =of g] {$h$};
      \node[inner, state] (i) [below =of h] {$i$};
    \end{tikzpicture}
  };
  \draw[very thick,orange,-] (a) -- (i);
  • 1
    https://tex.stackexchange.com/questions/47377/proper-nesting-of-tikzpicture-environments-reset-all-pgf-values-to-their-defaul: nesting tikzpictures is not supported, everything can happen... – Rmano May 15 '21 at 08:14

2 Answers2

3

Another way to use of matrix library at drawing your image:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,
                positioning}

\begin{document}

\begin{tikzpicture}[

M/.style = {matrix of math nodes,% nodes={circle, draw=gray, thick, minimum size=2em, text depth=0.25ex, inner sep=0pt}, row sep=2em, draw, thin } ] \matrix (m) [M] { a \ b \ c \ d \ e\ }; \matrix (n) [M, right=of m] { f \ g \ h \ i \ }; \draw[very thick,orange] (m-1-1) -- (n-4-1); \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517
2

Use matrix and judicious use of \\:

\begin{tikzpicture}[remember picture, %fixed by PROF
  inner/.style={circle,draw=black!50,fill=white!20,thick,inner sep=3pt},
  outer/.style={draw=black,fill=black!20,thick,inner sep=10pt}
  ]
  \node[matrix,draw=black] (A) {
      \node[inner, state] (a) {$a$};
      \node[inner, state] (b) [below =of a] {$b$};
      \node[inner, state] (c) [below =of b] {$c$};
      \node[inner, state] (d) [below =of c] {$d$};
      \node[inner, state] (e) [below =of d] {$e$};\\
  };
  \node[matrix,draw=black,right=of A] (B) {
      \node[inner, state] (f) {$f$};
      \node[inner, state] (g) [below =of f] {$g$};
      \node[inner, state] (h) [below =of g] {$h$};
      \node[inner, state] (i) [below =of h] {$i$};\\
  };
  \draw[very thick,orange,-] (a) -- (i);
\end{tikzpicture}

  • Could delete this, but maybe it will help someone – Bjørn Kjos-Hanssen May 15 '21 at 00:57
  • 2
    This is a possible, nice, smart and, in particular, correct way of doing this, apart from using scopes, chains etc. Yet, to be honest, this solution is great mainly because the original attempt, which nests tikzpictures, is basically the opposite of great. –  May 15 '21 at 01:18