为什么套印环境没有固定位置?

为什么套印环境没有固定位置?

overprint在 beamer 中使用了两列环境,当覆盖时它会向下移动,最后一张幻灯片有一些空间。我该如何解决这个问题。

\documentclass{beamer}
\usepackage{tikz}
\newcommand{\code}[1]{\footnotesize\tt #1}
\newcommand{\codealert}[1]{\alert{\code{#1}}}
\begin{document}
\begin{frame}
\begin{columns}
\begin{column}{.55\textwidth}
\code{\textbackslash begin\{tikzpicture\}}\\
\code{\textbackslash node[circle,draw](a) at (0,0)\{a\};}\\
\code{\textbackslash node[circle,draw](b) at (1,1)\{b\};}\\
\begin{overprint}
\onslide<1>{\codealert{\textbackslash draw[->](a) -- (b);}}\\
\onslide<2>{\codealert{\textbackslash draw[->](a) to (b);}}\\
\onslide<3>{\codealert{\textbackslash draw[->](a) -| (b);}}\\
\onslide<4>{\codealert{\textbackslash draw[->](a) |- (b);}}
\end{overprint}
\code{\textbackslash begin\{tikzpicture\}}
\end{column}
\begin{column}{.4\textwidth}
\tikz{
\draw (-1,-1) rectangle +(3,3);
\node [circle, draw] (a) at (0,0) {a};
\node [circle, draw] (b) at (1,1) {b};
\onslide<1>{\draw [->,red] (a) -- (b);}
\onslide<2>{\draw [->,red] (a) to (b);}
\onslide<3>{\draw [->,red] (a) -| (b);}
\onslide<4>{\draw [->,red] (a) |- (b);}
}
\end{column}
\end{columns}
\end{frame}
\end{document}

答案1

以下代码不会产生任何跳转;我在最后修复了一个小拼写错误,并移动了和删除,overprint这是不需要的(至少在这个例子中不需要):

\documentclass{beamer}
\usepackage{tikz}

\newcommand{\code}[1]{\footnotesize\ttfamily #1}
\newcommand{\codealert}[1]{\alert{\code{#1}}}

\begin{document}

\begin{frame}
\begin{columns}
\begin{column}{.55\textwidth}
\code{\textbackslash begin\{tikzpicture\}}\\
\code{\textbackslash node[circle,draw](a) at (0,0)\{a\};}\\
\code{\textbackslash node[circle,draw](b) at (1,1)\{b\};}\\
\onslide<1>{\codealert{\textbackslash draw[->](a) -- (b);}}\\
\onslide<2>{\codealert{\textbackslash draw[->](a) to (b);}}\\
\onslide<3>{\codealert{\textbackslash draw[->](a) -| (b);}}\\
\onslide<4>{\codealert{\textbackslash draw[->](a) |- (b);}}
\code{\textbackslash end\{tikzpicture\}}
\end{column}
\begin{column}{.4\textwidth}
\tikz{
\draw (-1,-1) rectangle +(3,3);
\node [circle, draw] (a) at (0,0) {a};
\node [circle, draw] (b) at (1,1) {b};
\onslide<1>{\draw [->,red] (a) -- (b);}
\onslide<2>{\draw [->,red] (a) to (b);}
\onslide<3>{\draw [->,red] (a) -| (b);}
\onslide<4>{\draw [->,red] (a) |- (b);}
}
\end{column}
\end{columns}
\end{frame}

\end{document}

在此处输入图片描述

如果每张幻灯片只有一条红线,请\only使用\onslide

\documentclass{beamer}
\usepackage{tikz}

\newcommand{\code}[1]{\footnotesize\ttfamily #1}
\newcommand{\codealert}[1]{\alert{\code{#1}}}

\begin{document}
\begin{frame}
\begin{columns}
\begin{column}{.55\textwidth}
\code{\textbackslash begin\{tikzpicture\}}\\
\code{\textbackslash node[circle,draw](a) at (0,0)\{a\};}\\
\code{\textbackslash node[circle,draw](b) at (1,1)\{b\};}\\
\begin{overprint}
\only<1>{\codealert{\textbackslash draw[->](a) -- (b);}\\}
\only<2>{\codealert{\textbackslash draw[->](a) to (b);}\\}
\only<3>{\codealert{\textbackslash draw[->](a) -| (b);}\\}
\only<4>{\codealert{\textbackslash draw[->](a) |- (b);}}
\code{\textbackslash end\{tikzpicture\}}
\end{overprint}
\end{column}
\begin{column}{.4\textwidth}
\tikz{
\draw (-1,-1) rectangle +(3,3);
\node [circle, draw] (a) at (0,0) {a};
\node [circle, draw] (b) at (1,1) {b};
\onslide<1>{\draw [->,red] (a) -- (b);}
\onslide<2>{\draw [->,red] (a) to (b);}
\onslide<3>{\draw [->,red] (a) -| (b);}
\onslide<4>{\draw [->,red] (a) |- (b);}
}
\end{column}
\end{columns}
\end{frame}

\end{document}

在此处输入图片描述

相关内容