[Tex/LaTex] Aligning TikZ trees with other nodes

nodestikz-pgf

I would like to align a TikZ tree with another node by considering the tree as a whole like as if it was a node with anchors. For the moment I am only able to align the root node of the tree, not the whole tree itself. I use PGF 2.10.

The following picture shows what I have:

what I have

What I want is that the left node and the tree are horizontally aligned and the arrow goes from the east anchor of the left node to the west anchor of the tree, i.e. more or less the left child of the root node as shown here:

what I want

Please ignore the outer border on both images.

Do you know a way to achieve this?

My test code is given below. I compile it with xelatex.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning,trees}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\newlength{\imagewidth}
\newlength{\imagescale}

\begin{document}    
\begin{tikzpicture}[
    ->, >=stealth', shorten >=1pt, semithick, node distance=1cm, level distance=7mm, level/.style={sibling distance=10mm/#1},
    block/.style = {draw, rectangle, rounded corners, minimum height=1cm},
    every node/.style={circle, draw, fill=none, anchor=north}
]

\node [block] (SOURCE DOCUMENT) {\parbox{2cm}{\centering source document}};

\node (SOURCE TREE)[right=of SOURCE DOCUMENT] {}
    child { node {} }
    child { node {} 
        child { node {} }
        child { node {} }
    };

\draw [->] (SOURCE DOCUMENT) edge (SOURCE TREE);
\end{tikzpicture}   
\end{document}

Best Answer

Using fit library you may create additional node, that would contain every node in your tree. After that use it's anchors to perform your justification.

Here's result of such solution:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning,trees,fit}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\newlength{\imagewidth}
\newlength{\imagescale}

\begin{document}
\begin{tikzpicture}[
    ->, >=stealth', shorten >=1pt, semithick, node distance=1cm, level distance=7mm, level/.style={sibling distance=10mm/#1},
    block/.style = {draw, rectangle, rounded corners, minimum height=1cm},
    every node/.style={circle, draw, fill=none, anchor=north}
]

\node (SOURCE TREE) {}
    child { node {} }
    child { node {} 
        child { node {} }
        child { node {} }
    };

\node[fit=(SOURCE TREE) (SOURCE TREE-1) (SOURCE TREE-2) (SOURCE TREE-2-1) (SOURCE TREE-2-2),
    draw=none, rectangle, inner sep=0] (whole tree) {};

\node[block, left=of whole tree] (SOURCE DOCUMENT) {\parbox{2cm}{\centering source document}};

\draw (SOURCE DOCUMENT) -- (whole tree);
\end{tikzpicture}   
\end{document}

enter image description here