如何更改 Beamer 文档中某一帧的背景颜色?我尝试过
\begin{frame}
\setbeamercolor{background canvas}{bg=violet}
% frame contents here
\end{frame}
但似乎并没有什么效果。
有人知道问题是什么吗?
答案1
在开始框架之前修改背景画布,而不是在框架内。
为了使颜色变化的效果保持局部,您可以在框架和该命令周围使用花括号,或者\begingroup ... \endgroup
。
{
\setbeamercolor{background canvas}{bg=violet}
\begin{frame}
% frame contents here
\end{frame}
}
答案2
将\setbeamercolor
命令放在框架外。这将改变每个后续框架的背景颜色。如果您只想更改该幻灯片,您可以将框架和命令放在{}
这是一个完整的例子:
\documentclass{beamer}
\begin{document}
\begin{frame}{A white frame}
\end{frame}
% Change all subsequent frames to violet
\setbeamercolor{background canvas}{bg=violet!20}
\begin{frame}{A violet frame}
\end{frame}
\begin{frame}{This frame is also violet}
\end{frame}
% But this frame only will be yellow: note { ... } around
% the \setbeamercolor and the frame to limit the scope
{\setbeamercolor{background canvas}{bg=yellow!20}
\begin{frame}{This frame is yellow}
\end{frame}
}
\begin{frame}{Subsequent frames will be violet}
\end{frame}
\end{document}
答案3
这里建议bg
在框架环境中添加一个选项,这样只需将该[bg]
选项添加到即可调用背景颜色frame
。
除了下面的模板外,我还没有测试过这一点,模板是通过随意拼凑线索拼凑起来的。将实际颜色作为论据,如[bg=blue]
,留给无聊的读者作为练习。
\documentclass{beamer}
\defbeamertemplate*{background canvas}{mydefault}
{%
\ifbeamercolorempty[bg]{background canvas}{}{\color{bg}\vrule width\paperwidth height\paperheight}% copied beamer default here
}
\defbeamertemplate*{background canvas}{bg}
{%
\color{lightgray!40}\vrule width\paperwidth height\paperheight% added bg color
}
\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background canvas}[mydefault]%
}
\makeatletter
\define@key{beamerframe}{bg}[true]{%
\setbeamertemplate{background canvas}[bg]%
}
\makeatother
\begin{document}
\begin{frame}
\frametitle{Normal}
\end{frame}
\begin{frame}[bg]
\frametitle{With bg}
\end{frame}
\begin{frame}
\frametitle{Normal}
\end{frame}
\end{document}
可以用图像而不是纯色来做类似的事情(现在偏离主题):
\documentclass{beamer}
\usepackage{graphicx}
\usepackage{tikz}
\pgfdeclareimage[width=\paperwidth]{mybackground}{brain}
%% As an option to frame
\defbeamertemplate*{background canvas}{mydefault}
{%
\ifbeamercolorempty[bg]{background canvas}{}{\color{bg}\vrule width\paperwidth height\paperheight}% copied beamer default here
}
\defbeamertemplate*{background canvas}{image}
{%
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle (\the\paperwidth, \the\paperheight);
\pgftext[at=\pgfpoint{0cm}{0cm}, left, base]{\pgfsetfillopacity{0.1}\pgfuseimage{mybackground}};
\end{tikzpicture}
}
\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background canvas}[mydefault]%
}
\makeatletter
\define@key{beamerframe}{image}[true]{%
\setbeamercovered{invisible}%
\setbeamertemplate{background canvas}[image]%
}
\makeatother%
\title[...]{My title}
\begin{document}
\begin{frame}[image]
\titlepage
\end{frame}
\section{Introduction}
\begin{frame}[plain]
Text here
\end{frame}
\end{document}