![在 Beamer 中将幻灯片背景设为可选项](https://linux22.com/image/339313/%E5%9C%A8%20Beamer%20%E4%B8%AD%E5%B0%86%E5%B9%BB%E7%81%AF%E7%89%87%E8%83%8C%E6%99%AF%E8%AE%BE%E4%B8%BA%E5%8F%AF%E9%80%89%E9%A1%B9.png)
我的自定义模板中有背景,我想在某些幻灯片中关闭它。理想情况下,我会使用 选项来执行此\begin{frame}
操作。我的模板大致基于Claudio Fiandrino 对“从头开始设计自定义 Beamer 主题”的回答。
我见过如何在投影仪框架中插入背景图像?和如何将背景图像仅包含在投影仪演示文稿的一页中?;我所寻找的本质上是后者的反面,但是干净利落(如果我正确使用这个模板,我不会是唯一使用它的人,所以我希望它是强大的)。
这对于 MWE 来说就是相当多的代码。最相关的部分可能是第一个,beaminnerthemecf.sty
:
\mode<presentation>
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox[inner sep=0] (0,0) rectangle(\paperwidth,\paperheight);
\node[anchor=north,opacity=0.25] (bkg) at (current page.north) {\includegraphics[width=\paperwidth,height=\paperheight]{example-image-a}};
\fill[color=red,anchor=north west] (0,\the\paperheight) rectangle(\the\paperwidth,0.85\paperheight);
\node[anchor= south east, red,align=right] at (0.975\paperwidth,0.025\paperheight){\normalsize\insertauthor\\[0.2em]\normalsize\insertdate};
\ifnum\thepage>1\relax%
\ifx\insertframesubtitle\@empty%
{\node[anchor=north west, white,font=\Large] at (0.025\paperwidth,0.975\paperheight){\insertframetitle};}
\else{%
\node[anchor=north west, white,font=\Large] at (0.025\paperwidth,0.985\paperheight){\insertframetitle};%
\node[anchor=north west, white,font=\large] at (0.025\paperwidth,0.925\paperheight){\insertframesubtitle};%
}%
\fi
\fi
\end{tikzpicture}
}
% Title page
\defbeamertemplate*{title page}{cf}[1][]{%
\begin{tikzpicture}[overlay, remember picture, shift={(current page.south west)}]
\useasboundingbox (current page.south west) rectangle(\paperwidth,\paperheight);
\node[anchor=center, red,inner sep=0,align=center,text width=0.8\paperwidth] at (0.5\paperwidth,0.5\paperheight){\inserttitle};
\end{tikzpicture}
}
% Items
\setbeamertemplate{items}[square]
\setbeamertemplate{sections/subsections in toc}[square]
\mode<all>
为了测试它,我们可以编译dummy.tex
:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\title{\Large{\textbf{There Is No Largest Prime Number}}}
\date[ISPN ’80]{27th International Symposium of Prime Numbers}
\author[Euclid]{Euclid of Alexandria \texttt{[email protected]}}
\usetheme{cf}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame} % This is where I'd like to turn off the background image
\frametitle{There Is No Largest Prime Number}
\framesubtitle{The proof uses \textit{reductio ad absurdum}.}
This is a test
\begin{enumerate}
\item Suppose $p$ were the largest prime number.
\item Let $q$ be the product of the first $p$ numbers.
\item Then $q+1$ is not divisible by any of them.
\item But $q + 1$ is greater than $1$, thus divisible by some prime
number not in the first $p$ numbers.
\end{enumerate}
\end{frame}
\end{document}
还需要beamerouterthemecf.sty
:
\mode<presentation>
% Frame title
\defbeamertemplate*{frametitle}{cf}[1][]{
}
\mode<all>
和beamercolorthemecf.sty
:
\mode<presentation>
% Settings
\setbeamercolor*{title page header}{fg=white}
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\setbeamercolor*{item}{fg=red}
\setbeamercolor*{normal text}{fg=black}
\mode<all>
答案1
您始终可以声明一个本地空背景。
\documentclass{beamer}
\setbeamertemplate{background}{
\includegraphics[height=\paperheight,width=\paperwidth]{example-image-a}
}
\begin{document}
\begin{frame}
Background image
\end{frame}
{%-> Starts scope where to apply following template
\setbeamertemplate{background}{}
\begin{frame}
No background image
\end{frame}
}%-> Ends scope where particular template has been applied.
\begin{frame}
Background image, again.
\end{frame}
\end{document}