![通过投影仪幻灯片改进内容](https://linux22.com/image/405341/%E9%80%9A%E8%BF%87%E6%8A%95%E5%BD%B1%E4%BB%AA%E5%B9%BB%E7%81%AF%E7%89%87%E6%94%B9%E8%BF%9B%E5%86%85%E5%AE%B9.png)
在此示例中:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{overlayarea}{\linewidth}{0.7\paperheight}
\centering
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 5);
\coordinate (B) at (-5, 5);
\only<1>
{
\draw (O) -- (B);
}
\only<2>
{
\draw (O) -- (B);
\draw (O) -- (A);
}
\only<3>
{
\draw (O) -- (B);
\draw (O) -- (A);
\draw (A) -- (B);
}
\end{tikzpicture}
\end{overlayarea}
\end{frame}
\end{document}
我在幻灯片上绘制了一幅愈发复杂的图画:
然而:
在每张幻灯片中,我都会重新绘制上一张幻灯片中绘制的所有内容。如何继承上一张幻灯片中的内容?
第一张幻灯片上的线条相对于后续幻灯片上的相同线条有位移。如何在每张幻灯片上强制使用相同的参考系统。
答案1
解决方案可以使用\onslide
:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 5);
\coordinate (B) at (-5, 5);
\onslide<1->{
\draw (O) -- (B);
}
\onslide<2->{
\draw (O) -- (A);
}
\onslide<3->{
\draw (A) -- (B);
}
\end{tikzpicture}
\end{frame}
\end{document}
答案2
overlay-beamer-styles
就是为此而制作的。与使用不同\only
,这通常可以避免跳跃,而无需添加硬编码的边界框(您需要猜测该边界框的坐标,如果您决定稍后添加路径,则需要调整该边界框)。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\begin{document}
\begin{frame}
\begin{overlayarea}{\linewidth}{0.7\paperheight}
\centering
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 5);
\coordinate (B) at (-5, 5);
\draw (O) -- (B);
\draw[visible on=<2->] (O) -- (A);
\draw[visible on=<3->] (A) -- (B);
\end{tikzpicture}
\end{overlayarea}
\end{frame}
\end{document}
如果您希望线连接看起来不错,也许像这样更好。(在本例中,您需要放大才能看到差异,但总的来说,在我看来这样更好。)
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\begin{document}
\begin{frame}
\begin{overlayarea}{\linewidth}{0.7\paperheight}
\centering
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 5);
\coordinate (B) at (-5, 5);
\draw[visible on=<1>] (O) -- (B);
\draw[visible on=<2>] (B) -- (O) -- (A);
\draw[visible on=<3->] (B) -- (O) -- (A) -- cycle;
\end{tikzpicture}
\end{overlayarea}
\end{frame}
\end{document}
如果您有许多要使用的路径,您可以定义一个样式,accumulate path
,它可以帮助您累积这些路径。您只需绘制这些路径,并且每当您希望此路径和所有后续路径仅出现在下一帧时,您都需要添加vis+
。您不需要任何范围或任何东西,只需vis+
。
\documentclass{beamer}
\usepackage{tikz}
\newcounter{Viesturs-step}
\resetcounteronoverlays{Viesturs-step}%
\usetikzlibrary{overlay-beamer-styles}
\tikzset{accumulate path/.style={/utils/exec=\setcounter{Viesturs-step}{#1},
every path/.append style={visible on=<\number\value{Viesturs-step}->}},
accumulate path/.default=1,
vis+/.style={/utils/exec=\stepcounter{Viesturs-step},
visible on=<\number\value{Viesturs-step}->}}
\begin{document}
\begin{frame}[t]
\centering
\begin{tikzpicture}[accumulate path]
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 5);
\coordinate (B) at (-5, 5);
\draw (O) -- (B);
\draw[red] (O) to[bend left] (B);
\draw[vis+] (O) -- (A);
\draw[red] (O) to[bend right] (A);
\draw[vis+] (A) -- (B);
\draw[red] (A) to[bend right] (B);
\end{tikzpicture}
\end{frame}
\end{document}
答案3
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{overlayarea}{\linewidth}{0.7\paperheight}
\centering
\begin{tikzpicture}
\useasboundingbox(-5.5,-.5)rectangle(6,5.5);%
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 5);
\coordinate (B) at (-5, 5);
\draw<1-> (O) -- (B);
\draw<2-> (O) -- (A);
\draw<3> (A) -- (B);
\end{tikzpicture}
\end{overlayarea}
\end{frame}
\end{document}