Reverse the order of pause when used with a stack
Instead of using \pause
I'd recommend using a key visible on
as defined in the preamble of the following MWE. The trick is to enclose each level of stack in a scope
environment, and pass the key visible on=<num>
to the environment to set the overlay effects. I also had to redefine the \cellptr
command in the drawstack
package to prevent the top right arrow to wiggle between frames.
MWE
\documentclass{beamer}
\usepackage{tikz}
\tikzset{
invisible/.style={opacity=0},
visible on/.style={alt={#1{}{invisible}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
},
}
\usepackage[nocolor]{drawstack}
\renewcommand{\cellptr}[1]{
\draw[<-,line width=0.7pt] (0,0) +(2,0) -- +(2.5,0) node[anchor=west] {#1};
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{scope}[visible on=<4->]
\stacktop{} \cellptr{top of stack}
\separator
\end{scope}
\begin{scope}[visible on=<3->]
\cell{c} \cellcomL{2};
\separator
\end{scope}
\begin{scope}[visible on=<2->]
\cell{b} \cellcomL{1};
\separator
\end{scope}
\begin{scope}[visible on=<1->]
\cell{a} \cellcomL{0};
\separator
\end{scope}
\end{tikzpicture}
\end{frame}
\end{document}
Output
A solution with a simple tabular:
\documentclass[table]{beamer}
\usepackage{fontspec}
\usepackage{libertine}
\usepackage{array}
\usetheme{Malmoe}
\begin{document}
\begin{frame}{Stack with a tabular}\arrayrulewidth=1pt
\begin{tabular}{@{} l |
>{\columncolor{black!10}\centering\rule[-2ex]{0pt}{5ex}}p{3cm} |@{} r}\cline{2-2}
& \ldots & $\longleftarrow$ top of stack \\\cline{2-2} \onslide<3->
2 & c & \\\cline{2-2} \onslide<2->
1 & b & \\\cline{2-2} \onslide<1->
0 & a & \\\cline{2-2}
\end{tabular}
\end{frame}
\end{document}
Another solution with a simple makebox
and without holes:
\documentclass[table]{beamer}
\usepackage{fontspec}
\usepackage{libertine}
\usepackage{array}
\usetheme{Malmoe}
\newcommand\MBox[2]{\makebox[1em]{#1}~\fbox{\makebox[3cm]{\rule[-2ex]{0pt}{5ex}#2}}}
\begin{document}
\begin{frame}{Stack with Boxes}\offinterlineskip
\onslide+<1->{\MBox{}{\ldots}$\longleftarrow$ top of stack\\}
\only<3-> {\MBox2c\\}
\only<2-> {\MBox1b\\}
\only<1-> {\MBox0a}
\end{frame}
\end{document}