In the beginning I want to ask why matrix is messed up in beamer, then @percusse gave the instructions to make it perform right.
Now the problem left is the two arrows before c4 and c7 seems not horizontal, is there a way to fixt it?
\documentclass{standalone}
%\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
%\begin{frame}[fragile]
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,row sep=3em,column sep=4em,minimum width=2em]
{
c_0 & c_1 & c_2 & c_3 \\
{} & c_4 & c_5 & c_6 \\
{} & c_7 & c_8 & & \\
};
\path[-stealth]
(m-1-1) edge node [above] {$a_0$} (m-1-2)
(m-1-2) edge node [above] {$a_1$} (m-1-3)
(m-1-3) edge node [above] {$a_2$} (m-1-4)
(m-2-1) edge node [above] {$a_3$} (m-2-2)
(m-2-2) edge node [above] {$a_4$} (m-2-3)
(m-2-3) edge node [above] {$a_5$} (m-2-4)
(m-3-1) edge node [above] {$a_6$} (m-3-2)
(m-3-2) edge node [above] {$a_7$} (m-3-3);
\end{tikzpicture}
%\end{frame}
\end{document}


\begin{frame}[fragile]or useampersand replacement=\&in the matrix and use & to separate the matrix entries – percusse Aug 30 '16 at 09:58