\setbeamercolor{background canvas}{bg=black}
如果我想更改背景颜色,使用可以正常工作。但是一旦我使用\setbeamertemplate{background canvas}{}
它,它就不再起作用了:
\documentclass{beamer}
\begin{document}
% as expected
\begin{frame}{Test}
white
\end{frame}
\setbeamercolor{background canvas}{bg=black}
\begin{frame}{Test}
\textcolor{white}{black}
\end{frame}
\setbeamercolor{background canvas}{bg=}
\begin{frame}{Test}
white again
\end{frame}
% confusing
\setbeamertemplate{background canvas}{}
\setbeamercolor{background canvas}{bg=black}
\begin{frame}{Test}
should be black
\end{frame}
\end{document}
编辑:我为什么要这样做?
我有时会使用这样的代码
\setbeamertemplate{background canvas}{\includegraphics[width=\paperwidth]{picture.jpg}}
使用图片填充背景。我使用
\setbeamertemplate{background canvas}{}
我还能怎样清除图片?
好的:
好的:
好的:
错误如下:
有任何想法吗?
答案1
Andrew Swann 的回答解释了为什么会发生这种情况,但我认为您可能会发现了解您可能想要做什么很有用。我不确定您通过将模板设置为空来实现什么,但可能您真的只是想消除标题/脚注等,以便幻灯片的整个区域都可用于内容。因此,我对您的示例进行了一些修改,以显示一些可能性:
\documentclass{beamer}
\begin{document}
% as expected
\begin{frame}{Test}
white
\end{frame}
\setbeamercolor{background canvas}{bg=black}
\begin{frame}{Test}
\textcolor{white}{black}
\end{frame}
\setbeamercolor{background canvas}{bg=}
\begin{frame}{Test}
white again
\end{frame}
% confusing
\setbeamercolor{background canvas}{bg=black}
\begin{frame}[plain]{Test}
Perhaps you just wanted to use a \texttt{plain} frame rather than eliminating the background altogether.
\end{frame}
\setbeamertemplate{background canvas}{}
\setbeamercolor{background canvas}{bg=red}
\begin{frame}{Test}
As others have explained, the template is now completely empty so the colour specification has no effect.
\end{frame}
\setbeamertemplate{background canvas}[default] % <--- Important
\begin{frame}{Test}
Now the template is reset to default, the colour specification earlier changes the background to red.
\end{frame}
\end{document}
答案2
模板是制作背景beamer
的background canvas
代码。默认情况下
\defbeamertemplate*{background canvas}{default}
{%
\ifbeamercolorempty[bg]{background canvas}{}{\color{bg}\vrule width\paperwidth height\paperheight}%
}
如您所见,它包含使用键的代码bg
。您的命令
\setbeamertemplate{background canvas}{}
删除此代码,现在该选项bg
未使用,因此没有效果。