# Tikz positioning inside matrix node

I have created a figure for tikz that looks like this:

But when I add it inside a matrix node it became like this:

Why does this happen?

My code for the first is:

\begin{tikzpicture}
\node[](users){\includegraphics[scale=0.5]{icons/user.png} };
\end{tikzpicture}


My code for the second is:

\begin{tikzpicture}
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,rectangle, rounded corners,minimum width=1.5cm,minimum height=3cm]
\tikzstyle{fancytitle} =[fill=red, text=white,rounded corners]
\node [matrix,mybox] (data){
\node[minimum size=2cm]{};
\node[](users){\includegraphics[scale=0.5]{icons/user.png} };
\\
};
\node[fancytitle, right=10pt] at (data.north west) {Data};
\end{tikzpicture}

-
Do you really need to place \nodes inside \nodes? If you are only trying to box the first diagrams, this can be done in different, more appropriate ways. – Gonzalo Medina May 6 '14 at 14:23
Could you please give me some info related to this? I used node inside node just for the box – nikosdi May 6 '14 at 14:38

Next code shows how to draw this diagram with a matrix.

If you use a matrix don't need to use positioning, all nodes are adjusted according to rows and columns with certain column sep and row sep. In this case default column and row separation is used, except between first and second row where a particular separation has been fixed with \\[1cm].

A matrix is also a node, therefore all options applied to matrix node are also applied to inner nodes. So minimum width and minimum height in mybox fixes minimum width and height of inner nodes. We can change it with nodes={...} at the end of matrix options declaration. In any case I think it's better not using minimum width/height in matrix options because the matrix will be big enough to encompass all inner nodes.

Contents text below google icon has been drawn as a label instead of a regular node.

I've also changed tikzstyle to tikzset. Please look at Should \tikzset or \tikzstyle be used to define TikZ styles?

I've used a matrix because OP did it. There exist some other solutions to get similar results: Place icons and surround them with fit library help, draw inner figure inside a tcolorbox or mdframe, ...

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

\tikzset{mybox/.style={draw=red, fill=blue!20, very thick,
rectangle, rounded corners,
minimum width=1.5cm,minimum height=3cm},
fancytitle/.style={fill=red, text=white,rounded corners}}

\begin{document}

\begin{tikzpicture}
\node [matrix,mybox, nodes={minimum height=0pt}] (data){
&
\node[](users){\includegraphics[scale=0.25]{user} }; & \\[1cm]

\\
};
\node[fancytitle, right=10pt] at (data.north west) {Data};
\end{tikzpicture}

\end{document}


2nd version: No matrix but positioning and background fit node:

\begin{tikzpicture}

\node (users){\includegraphics[scale=0.25]{user}};