我有以下代码来遍历算法的各个部分:
\documentclass{beamer}
\usetheme{default}
\usepackage[]{algorithm2e}
\def\HiLi{\leavevmode\rlap{\hbox to \hsize{\color{yellow!50}\leaders\hrule height .8\baselineskip depth .5ex\hfill}}}
\title{Beamer Template}
\begin{document}
\begin{frame}
\frametitle{}
Some text...
\begin{overlayarea}{\textwidth}{\textheight}
\begin{center}
\begin{minipage}[H]{.85\textwidth}
\begin{algorithm}[H]
\SetKwInOut{Input}{Input}
\only<1>{\HiLi}\Input{$G$, $W$}
\only<2>{\HiLi}$Q \leftarrow V$\;
\only<3>{\HiLi}$key[v] \leftarrow \infty$ for all $v \in V$\;
\only<4>{\HiLi}$key[s] \leftarrow 0$ for some arbitrary $s \in V$\;
\only<5>{\HiLi}\While{$Q \neq \emptyset$} {
\only<6>{\HiLi}$u \leftarrow ${\sc Extract-Min}$(Q)$\;
\only<7>{\HiLi}\For{each node $v$ in Adj$[u]$}{
\only<8>{\HiLi}\If{$v \in Q$ and $w(u,v) < key[v]$} {
\only<9>{\HiLi}$key[v] \leftarrow w(u,v)$ // {\sc Decrease-Key}\;
\only<10>{\HiLi}$\pi[v] \leftarrow u$\;
}
}
}
\end{algorithm}
\end{minipage}
\end{center}
\end{overlayarea}
\end{frame}
\end{document}
随着突出显示沿行向下移动,突出显示的行也会移动。我尝试使用 \setspace 增加行间距,但没有帮助。我该如何阻止这种情况发生?
答案1
这是因为高亮区域太高太深。通过反复试验,我找到了可以解决这个问题的值。
\def\HiLi{\leavevmode\rlap{\hbox to \hsize{\color{yellow!50}\leaders\hrule height .55\baselineskip depth .4ex\hfill}}}
\documentclass{beamer}
\usetheme{default}
\usepackage[]{algorithm2e}
\def\HiLi{\leavevmode\rlap{\hbox to \hsize{\color{yellow!50}\leaders\hrule height .55\baselineskip depth .4ex\hfill}}}
\title{Beamer Template}
\begin{document}
\begin{frame}
\frametitle{}
Some text...
\begin{overlayarea}{\textwidth}{\textheight}
\begin{center}
\begin{minipage}[H]{.85\textwidth}
\begin{algorithm}[H]
\SetKwInOut{Input}{Input}
\only<1>{\HiLi}\Input{$G$, $W$}
\only<2>{\HiLi}$Q \leftarrow V$\;
\only<3>{\HiLi}$key[v] \leftarrow \infty$ for all $v \in V$\;
\only<4>{\HiLi}$key[s] \leftarrow 0$ for some arbitrary $s \in V$\;
\only<5>{\HiLi}\While{$Q \neq \emptyset$} {
\only<6>{\HiLi}$u \leftarrow ${\sc Extract-Min}$(Q)$\;
\only<7>{\HiLi}\For{each node $v$ in Adj$[u]$}{
\only<8>{\HiLi}\If{$v \in Q$ and $w(u,v) < key[v]$} {
\only<9>{\HiLi}$key[v] \leftarrow w(u,v)$ // {\sc Decrease-Key}\;
\only<10>{\HiLi}$\pi[v] \leftarrow u$\;
}
}
}
\end{algorithm}
\end{minipage}
\end{center}
\end{overlayarea}
\end{frame}
\end{document}