# Position two stacked tikz matrices

I would like to take two TikZ matrix, possibly of different dimensions and stack them. My demo code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix [matrix of nodes,row sep=-\pgflinewidth,column 2/.style={nodes={rectangle,draw,minimum width=3em}}]
{
0   & 6 \\
};
\matrix [matrix of nodes,row sep=-\pgflinewidth,column 2/.style={nodes={rectangle,draw,minimum width=3em}}]
{
1   & 3 \\
};
\end{tikzpicture}
\end{document}


There should be some space between the matrices and they should be aligned. I've tried to use below of but it doesn't seem to work...

-

You can also use a scope and shift the entire content.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix [matrix of nodes,row sep=-\pgflinewidth,column 2/.style={nodes={rectangle,draw,minimum width=3em}}]
{
0   & 6 \\
};
\begin{scope}[yshift=-1cm]
\matrix [matrix of nodes,row sep=-\pgflinewidth,column 2/.style={nodes={rectangle,draw,minimum width=3em}}]
{
1   & 3 \\
};
\end{scope}
\end{tikzpicture}
\end{document}


-
is there a way to make this work if the column styles include anchor=base west? If one scoped node is wider than the other scoped nodes, the aligned positions are different. –  Trevor Alexander Jan 14 '14 at 21:54
@TrevorAlexander It is possible by choosing proper shift distances and anchors. It is hard to say without some code though. –  Harish Kumar Jan 14 '14 at 22:23
I'll put it in another question. Thanks. –  Trevor Alexander Jan 14 '14 at 22:25

A matrix is just really a node, so if you name the top matrix (Top) then you can use below of=Top in the other matrix to position it:

## Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix  [matrix of nodes,row sep=-\pgflinewidth,column 2/.style={nodes={rectangle,draw,minimum width=3em}}] (Top)
{
0   & 6 \\
};
\matrix [matrix of nodes,row sep=-\pgflinewidth,column 2/.style={nodes={rectangle,draw,minimum width=3em}}, below of=Top]
{
1   & 3 \\
};
\end{tikzpicture}
\end{document}

-
What happened to good ol' at (3,2)? :P –  percusse Nov 17 '12 at 0:11
As I pointed out, I tried to use below of and it doesn't work. The matrices actually overlap. –  JonSlaughter Nov 17 '12 at 0:17
@JonSlaughter: Is that comment directed at me or percusse? If so, and this solution does not work for you, it would be helpful if you posted a more realistic example –  Peter Grill Nov 17 '12 at 0:19
@JonSlaughter As Peter showed it works without any complication. What is it that doesn't work? –  percusse Nov 17 '12 at 0:21
Well, the example is more complex. Why it doesn't work I have no idea. Harish's method worked so I'll go with that. I don't like necessarily hard coding the offset but it will do. My matricies are just normal matrices not much different than above except they use math nodes. –  JonSlaughter Nov 17 '12 at 0:21