6

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?

enter image description here

\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}
icycandy
  • 493
  • 2
    use \begin{frame}[fragile] or use ampersand replacement=\& in the matrix and use & to separate the matrix entries – percusse Aug 30 '16 at 09:58

1 Answers1

8

enter image description here

In the first column use phantom nodes and delete surplus ampersand in the last row.:

\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 \\
      {\phantom{c_0}}   & c_4 & c_5 & c_6 \\
      {\phantom{c_0}}   & 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}

or use for arrow start coordinate (m-1-1.east |- m-2-2) and (m-1-1.east |- m-3-2):

  \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-1-1.east |- m-2-2) 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-1-1.east |- m-3-2) edge node [above] {$a_6$} (m-3-2)
      (m-3-2) edge node [above] {$a_7$} (m-3-3);
Zarko
  • 296,517
  • @Zarko is it possible to draw lines around this matrix? by the way, nice question and nice answer. – nima Aug 30 '16 at 14:49
  • yes, it is possible and very simple: \matrix (m) [matrix of math nodes, row sep=3em, column sep=4em, minimum width=2em, draw] % added "draw" for frame around matrix – Zarko Aug 30 '16 at 15:12