我只想在beamer
标题页中添加背景。我可以按如下方式添加.tex
:
\setbeamertemplate{background canvas}{
\includegraphics[width=\paperwidth,height=\paperheight]{img/bg-first.pdf}
}
但我不想在 中运行上述命令.tex
,而是在.sty
文件中运行。感谢您指出如何在.sty
文件中添加上述命令。
请参阅下面的.sty
和.tex
文件(它们都非常简单)。
main.sty
\mode<presentation>
\DeclareOptionBeamer{titlepage}{\PassOptionsToPackage{titlepage=#1}{beamertheme-Inner}}
\ProcessOptionsBeamer
\usetheme{Inner}
\usetheme{Outer}
\setbeamertemplate{navigation symbols}{}
\mode
<all>
inner.sty
\mode<presentation>
\DeclareOptionBeamer{titlepage}{\def\beamer@titlepage{#1}}
\defbeamertemplate*{titlepage}
{
\begin{center}
\usebeamerfont{title}\inserttitle
\ifx\insertsubtitle\@empty
\else
\vskip2ex
\usebeamerfont{subtitle}\insertsubtitle
\fi
\ifx\insertauthor\@empty
\else
\vskip2ex
\usebeamerfont{author}\insertauthor
\fi
\ifx\insertdate\@empty
\else
\vskip2ex
\usebeamerfont{date}\insertdate%
\fi
\end{center}
\vfill
}
.tex
文件
\usetheme{Afnic}
\title{An example theme for \LaTeX{} Beamer}
\author{Sandoche}
\date{February 29, 2012}
\begin{document}
\begin{frame}[plain]
\maketitle
\end{frame}
\AtBeginSection[]
{
\begin{frame}
\frametitle{Outline}
\tableofcontents[currentsection]
\end{frame}
}
答案1
您可以检查帧号:
\setbeamertemplate{background canvas}{%
\ifnum\c@framenumber=1%
% On title page
\fi%
}
您可以扩展此功能以将内容设置为除标题之外的所有框架:
\setbeamertemplate{background canvas}{%
\ifnum\c@framenumber=1%
% On title page
\else%
% Other frames background
\fi%
}
扩大的视野
根据要求,该版本还检查最后一帧。我们用etoolbox
它来启用嵌套的 if 语句。
\documentclass{beamer}
\usepackage{etoolbox}
\makeatletter
\setbeamertemplate{background canvas}{%
\ifnumequal{\c@framenumber}{1}{%
% First frame
\color{red!50}\rule{\paperwidth}{\paperheight}
}{%
\ifnumequal{\c@framenumber}{\inserttotalframenumber}{
% Last frame
\color{orange!50}\rule{\paperwidth}{\paperheight}
}{%
% Other frames
\color{green!50}\rule{\paperwidth}{\paperheight}
}%
}%
}
\makeatother
\begin{document}
\frame{1}
\frame{2}
\frame{3}
\frame{4}
\end{document}
\c@framenumber
是当前帧的计数器,\inserttotalframenumber
保存最后一帧的编号。当然可以省略该Other frames
部分
答案2
Tobi 的解决方案有一些明显的缺点。它只在标题页实际上是第一帧时才有效,并且在不使用标题页时也会产生问题。一个稍微好一点的解决方案是在命令中使用\AddToShipoutPictureFG*
命令。因此,提问者的代码将是:eso-pic
\setbeamertemplate{title page}
inner.sty
\setbeamertemplate{title page}
{
\AddToShipoutPictureFG*{\includegraphics[width=\paperwidth,height=\paperheight]{img/bg-first.pdf}}
\begin{center}
\usebeamerfont{title}\inserttitle
\ifx\insertsubtitle\@empty
\else
\vskip2ex
\usebeamerfont{subtitle}\insertsubtitle
\fi
\ifx\insertauthor\@empty
\else
\vskip2ex
\usebeamerfont{author}\insertauthor
\fi
\ifx\insertdate\@empty
\else
\vskip2ex
\usebeamerfont{date}\insertdate%
\fi
\end{center}
\vfill
}