Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to draw a graph and have a separate graph within one of the outer nodes. I seen this question, but I don't understand how the matrix nodes will help me. I would also like to draw edges between the outer nodes to the inner nodes.

Could someone please make a quick example of with 3 nodes, where one of the nodes contains a subgraph with 3 nodes?

share|improve this question

2 Answers 2

up vote 16 down vote accepted

Here's a little example: two "outer" nodes, each one containing a graph (formed with "inner" nodes) and some edges and arrows connecting outer nodes to outer nodes, and inner nodes from one graph to inner nodes of the other; the remember picture option lets you access inner and outer nodes at any time:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}[remember picture,
  inner/.style={circle,draw=blue!50,fill=blue!20,thick,inner sep=3pt},
  outer/.style={draw=green,fill=green!20,thick,inner sep=10pt}
  ]
  \node[outer,draw=green] (A) {
    \begin{tikzpicture}
      \node [inner,draw=blue] (ai)  {A1};
      \node [inner,draw=blue,below=of ai] (aii) {A2};
      \node [inner,draw=blue,right=of aii] (aiii) {A3};
      \draw[red,thick] (ai) -- (aii) -- (aiii) -- (ai);
    \end{tikzpicture}
  };
  \node[outer,draw=green,right=of A] (B) {
    \begin{tikzpicture}
      \node [inner,draw=blue] (bi)  {B1};
      \node [inner,draw=blue,below=of bi] (bii) {B2};
      \node [inner,draw=blue,right=of bii] (biii) {B3};
      \node [inner,draw=blue,right=of bi] (biv) {B4};
      \draw[red,thick] (bi) -- (bii) -- (biii) -- (biv) -- (bi) -- (biii);
    \end{tikzpicture}
  };
  \draw[thick,orange,->] (ai) -- (bii);
  \draw[orange,->] (aiii) -- (bi);
  \draw[orange,->] (A.90) -- ($(A.90)+(0,1)$) -| (B);
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Yep, this did it; remember picture was the key! Thanks! –  gablin Sep 7 '11 at 19:11
    
This does work with pdflatex but not with latex--dvipdf. See here: tex.stackexchange.com/q/186583/34812 –  user34812 Jun 25 at 15:24

I don't know the kind of problems that OP has with TiKZ matrices but Gonzalo's example is the kind of graph where a matrix is really helpful.

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

\begin{document}

\begin{tikzpicture}[
  inner/.style={circle,draw=blue!50,fill=blue!20,thick,inner sep=3pt},
  outer/.style={draw=green,fill=green!20,thick,inner sep=10pt, column sep=1cm, row sep=1cm}
  ]
  \matrix (A) [matrix of nodes, outer, nodes={inner}]{
    A1 \\
    A2 & A3\\
  };

  \matrix (B) [matrix of nodes, outer, nodes={inner}, right=of A]{
    B1 & B4\\
    B2 & B3\\
  };

  \draw[red, thick] (A-1-1)--(A-2-1)--(A-2-2)--(A-1-1);
  \draw[red, thick] (B-1-1)--(B-1-2)--(B-2-2)--(B-2-1)--(B-1-1);
  \draw[thick, orange,->] (A-1-1)--(B-2-1);
  \draw[thick, orange,->] (A-2-2)--(B-1-1);
  \draw[thick, orange,->] (A.north)--([yshift=1cm]A.north)-|(B);
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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