我想使用LaTeX beamer创建演示文稿,其中有两种不同的幻灯片模板/布局:一种是带有背景图像的幻灯片,另一种是没有指定背景图像的幻灯片模板/布局。
是否有什么技巧可以在beamer中实现这一点?
是否有什么技巧可以在beamer中实现这一点?
\documentclass{beamer}
\defbeamertemplate{background canvas}{mydefault}{%
\includegraphics[width=1cm]{example-image-duck}
}
\defbeamertemplate{background canvas}{fullimage}{%
\includegraphics[width=\paperwidth]{example-image-duck}
}
\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background canvas}[mydefault]%
}
\makeatletter
\define@key{beamerframe}{fullimage}[true]{%
\setbeamertemplate{background canvas}[fullimage]%
}
\makeatother
\begin{document}
\begin{frame}
left
\end{frame}
\begin{frame}[fullimage]
right
\end{frame}
\begin{frame}
is left again
\end{frame}
\end{document}
基本上,这归结于在每个\begin{frame}...\end{frame}
之前放置\usebackgroundtemplate
。
{\usebackgroundtemplate{\includegraphics[width=\paperwidth]{background.jpg}}
在你的\begin{frame}
之前直接放置。
如果我理解正确,问题是如何同时生成两份演示文稿。为此,您可以使用一些低级别的TeX命令和几个文件。
在 Presentation.tex
中可能会有
%&pdftex
\relax
\immediate\write18{pdflatex -synctex=1 PresentationWithBG.tex}
\relax
\immediate\write18{pdflatex -synctex=1 PresentationWithoutBG.tex}
\end
这是唯一一个需要在上面运行latex的文件,您可以使用pdftex --shell-escape Presentation.tex
来运行。 但您还需要以下内容。
在PresentationWithBG.tex
中(请注意,在每个帧之前实际上不需要使用\usebackgroundtemplate
):
\documentclass{beamer}
\setbeamercolor{background canvas}{bg=}
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{<your_background_fig>}}
\input{PresentationContent}
PresentationWithoutBG.tex
文件中:\documentclass{beamer}
\input{PresentationContent}
PresentationContent.tex
中:\begin{document}
[All your actual presentation goes here...]
\end{document}
当你运行pdftex --shell-escape Presentation.tex
时,你会得到PresentationWithBG.pdf
和PresentationWithoutBG.pdf
。
请注意,在Presentation.tex
中的%&pdftex
确保无论哪个版本的TeX正在运行,都会切换到正确的模式。实际上,你可以使用pdflatex
来运行它。