我正在使用包在 beamer 中绘制堆栈drawstack
。我想使用 来显示堆栈的演变pause
。在 中tikzpicture
,pause
向前移动,但堆栈以相反的顺序绘制。我如何正确设置暂停以显示堆栈的演变。我可以想到使用多个帧分别显示演变的解决方法,但有没有更简洁的方法来做到这一点?
\documentclass{beamer}
\usepackage{tikz}
\usepackage[nocolor]{drawstack}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\stacktop{} \cellptr{top of stack}
\separator
\cell{c} \cellcomL{2};
\separator
\cell{b} \cellcomL{1};
\separator
\cell{a} \cellcomL{0};
\separator
\end{tikzpicture}
\end{frame}
\end{document}
答案1
我建议不要使用,而是使用以下 MWE 序言中定义的\pause
键。诀窍是将每个堆栈级别封闭在一个环境中,并将键传递给环境以设置叠加效果。我还必须重新定义包中的命令,以防止右上箭头在帧之间摆动。visible on
scope
visible on=<num>
\cellptr
drawstack
平均能量损失
\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}
输出
答案2
一个具有简单表格的解决方案:
\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}
另一种简单makebox
且无孔的解决方案:
\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}