在此图中,您可以看到在 Powerpoint 中完成的标题页、章节页和内容页:
如何修改此代码,以便部分页面具有图像上显示的背景?我可以稍后自己进行文本定位。
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz, datetime, textpos}
\yyyymmdddate \renewcommand{\dateseparator}{.}
\definecolor{MedianBrown}{RGB}{119,95,85}
\definecolor{MedianLightBrown}{RGB}{235,221,195}
\definecolor{MedianLightBlue}{RGB}{148,182,210}
\definecolor{MedianOrange}{RGB}{221,128,71}
\setbeamercolor*{title page header}{fg=white}
\setbeamercolor*{title}{fg=MedianLightBrown}
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\setbeamercolor*{item}{fg=MedianOrange}
\setbeamercolor*{frametitle}{fg=MedianBrown}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\ifnum\thepage>1\relax% Not the title page
\fill[color=MedianOrange] (0,8) rectangle(0.8,8.3);
\fill[color=MedianLightBlue] (0.9,8) rectangle(\the\paperwidth, 8.3);
\else% Title page
\fill[color=MedianBrown] (0,1.5) rectangle (\the\paperwidth,\the\paperheight);
\fill[color=MedianOrange] (0,0.1) rectangle(3.45,1.4);
\fill[color=MedianLightBlue] (3.55,0.1) rectangle(\the\paperwidth,1.4);
\fi
\end{tikzpicture}
}
\setbeamertemplate{title page}
{
\begin{textblock*}{12cm}(3cm,2.8cm)
\begin{beamercolorbox}[wd=8cm]{title page header}
\usebeamerfont{title}\usebeamercolor{title}\inserttitle%
\end{beamercolorbox}%
\end{textblock*}
\begin{textblock*}{12cm}(-0.5cm,4.9cm)
\begin{beamercolorbox}{date}
\usebeamerfont{date}\insertdate%
\end{beamercolorbox}
\end{textblock*}
\begin{textblock*}{9cm}(3cm,4.9cm)
\begin{beamercolorbox}{author}
\usebeamerfont{author}\insertauthor%
\end{beamercolorbox}
\end{textblock*}
}
\setbeamertemplate{frametitle}
{
\vskip0.3cm
\begin{beamercolorbox}{frametitle}
\insertframetitle
\end{beamercolorbox}
}
\setbeamertemplate{items}[square]
\setbeamertemplate{sections/subsections in toc}[square]
\author{Author Name}
\title{Quite A Long Title For A Simple Beamer Presentation}
\date{\today}
\begin{document}
\frame{\maketitle}
\section{Introduction}
\frame{\sectionpage}
\begin{frame}{My presentation is about\ldots}
\begin{itemize}
\item Some stuff
\item And some other stuff
\end{itemize}
\end{frame}
\end{document}
答案1
我也会添加我的答案,方法与 Bordaigorl 相同,但涉及的代码较少。
我们的想法是创建另一个命令\setbeamertemplate{background}
并将其嵌入到自定义命令中,以代替\frame{\sectionpage}
自定义命令将重新定义背景,然后重新定义section page
模板。作为示例,我使用tikzpicture
重新定位节头。
这是自定义命令:
\newcommand{\mysectionpage}{
\begingroup
\setbeamertemplate{background}{
\begin{tikzpicture} %edit this tikzpicture to customize the size and colors of the background rectangles
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\fill[color=MedianOrange] (0,7) rectangle(0.8,8);
\fill[color=MedianLightBlue] (0.9,7) rectangle(\the\paperwidth, 8);
\end{tikzpicture}
}
\setbeamercolor{section page}{fg=white}
\setbeamertemplate{section page}{
\begin{tikzpicture} %edit this tikzpicture to customize the appearance of the section heading
\node[overlay] at (1,2) {\insertsectionhead};
\end{tikzpicture}
}
\frame{\sectionpage}
\endgroup
}
其余的前言代码保持不变。文档正文将如下所示:
\begin{document}
\frame{\maketitle}
\section{Introduction}
\mysectionpage %new code
\begin{frame}{My presentation is about\ldots}
\begin{itemize}
\item Some stuff
\item And some other stuff
\end{itemize}
\end{frame}
\end{document}
结果是:
答案2
另一种选择遵循与 MWE 相同的模式,即使用条件语句一劳永逸地定义背景。我不喜欢这种方法,因为它不太模块化,但既然 @dcmst 问了,这里有一个带条件语句的解决方案。
首先,让我们为部分页面引入一个新的条件,并将其设置为 false
\newif\ifinsectionframe
\insectionframefalse
现在我们可以background
按如下方式更改模板
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\ifnum\thepage>1\relax% Not the title page
\ifinsectionframe%
\node {Some background}; %% INSERT YOUR GRAPHICS HERE
\else%
\fill[color=MedianOrange] (0,8) rectangle(0.8,8.3);
\fill[color=MedianLightBlue] (0.9,8) rectangle(\the\paperwidth, 8.3);
\fi%
\else% Title page
\fill[color=MedianBrown] (0,1.5) rectangle (\the\paperwidth,\the\paperheight);
\fill[color=MedianOrange] (0,0.1) rectangle(3.45,1.4);
\fill[color=MedianLightBlue] (3.55,0.1) rectangle(\the\paperwidth,1.4);
\fi
\end{tikzpicture}
}
然后我们可以创建一个\sectionframe
宏,在创建具有部分页面的框架之前设置相应的标志:
\newcommand{\sectionframe}{
\insectionframetrue
\frame{\sectionpage}
\insectionframefalse
}
然后如果您使用\sectionframe
而不是\frame{\sectionpage}
您将获得预期的效果。
关于检测标题页的条件的说明:我建议创建一个新的 if\ifintitleframe
而不是检查页码;除了语义上更合理之外,它还更灵活,因为您现在可以在任意页面(甚至多个)上拥有标题框,而不是强制它在第一页上。
答案3
问题是,部分页面模板在框架内被“调用”,但背景模板只能在启动框架之前更改。此外,设置标志修补\sectionpage
可能不起作用,因为它会在背景排版后设置它们。
因此,最简单的解决方案是定义一个宏来创建该部分框架(而不是页面)这样您可以在启动框架之前注入背景更改代码。
首先让我们介绍几个改变背景的宏:
\newcommand{\setslidebg}{
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\fill[color=MedianOrange] (0,8) rectangle(0.8,8.3);
\fill[color=MedianLightBlue] (0.9,8) rectangle(\the\paperwidth, 8.3);
\end{tikzpicture}
}
}
\newcommand{\setsecbg}{
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\node {Something else};
\end{tikzpicture}
}
}
\newcommand{\settitlebg}{
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
\fill[color=MedianBrown] (0,1.5) rectangle (\the\paperwidth,\the\paperheight);
\fill[color=MedianOrange] (0,0.1) rectangle(3.45,1.4);
\fill[color=MedianLightBlue] (3.55,0.1) rectangle(\the\paperwidth,1.4);
\end{tikzpicture}
}
}
\setslidebg
您可以在其中替换 tikzcode 来\setsecbg
生成所需的图形。
然后您可以简单地创建宏\titleframe
,\sectionframe
如下所示:
\newcommand{\titleframe}{
\settitlebg
\frame{\maketitle}
\setslidebg
}
\newcommand{\sectionframe}{
\setsecbg
\frame{\sectionpage}
\setslidebg
}
所以现在您只需写入\titleframe
而不是\frame{\maketitle}
并相应地设置背景即可。
答案4
我在设计中遇到了同样的问题我的 Beamer 主题。最后我找到了一个解决方案:使用adjustbox
包让你的标题页和章节页图片填满整个页面。
在标题/章节页面模板中,您可以使用\node
命令添加标题、作者、日期和章节名称。因此textpos
不需要包。
另外,您可以使用\AtBeginSection
命令在每个之前添加章节页面\section
。
最后,可以省略坐标\the
之前\paperwidth
和\paperheight
内部的命令。tikz
% -*- coding: utf-8 -*-
\documentclass{beamer}
\usepackage{tikz,datetime,adjustbox}
\yyyymmdddate \renewcommand{\dateseparator}{.}
\definecolor{MedianBrown}{RGB}{119,95,85}
\definecolor{MedianLightBrown}{RGB}{235,221,195}
\definecolor{MedianLightBlue}{RGB}{148,182,210}
\definecolor{MedianOrange}{RGB}{221,128,71}
\setbeamercolor*{title page header}{fg=white}
\setbeamercolor*{title}{fg=MedianLightBrown}
\setbeamercolor*{author}{fg=white}
\setbeamercolor*{date}{fg=white}
\setbeamercolor*{item}{fg=MedianOrange}
\setbeamercolor*{frametitle}{fg=MedianBrown}
\setbeamercolor*{section page}{fg=white}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{background}{
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\paperwidth,\paperheight);
\fill[color=MedianOrange] (0,8) rectangle(0.8,8.3);
\fill[color=MedianLightBlue] (0.9,8) rectangle(\paperwidth, 8.3);
\end{tikzpicture}
}
\setbeamertemplate{title page}{%
\nointerlineskip
\begin{adjustbox}{width=\paperwidth,center}
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle(\paperwidth,\paperheight);
\fill[color=MedianBrown] (0,1.5) rectangle (\paperwidth,\paperheight);
\fill[color=MedianOrange] (0,0.1) rectangle(3.45,1.4);
\fill[color=MedianLightBlue] (3.55,0.1) rectangle(\paperwidth,1.4);
\node[text width=0.8\paperwidth,right] at (4,3) {
\begin{beamercolorbox}[wd=8cm]{title page header}
\usebeamerfont{title}\usebeamercolor{title}\inserttitle%
\end{beamercolorbox}%
};
\node[text width=0.2\paperwidth,right] at (1,0.7) {
\begin{beamercolorbox}{date}
\usebeamerfont{date}\insertdate%
\end{beamercolorbox}
};
\node[text width=0.8\paperwidth,right] at (4,0.7) {
\begin{beamercolorbox}{author}
\usebeamerfont{author}\insertauthor%
\end{beamercolorbox}
};
\end{tikzpicture}
\end{adjustbox}
}
\setbeamertemplate{section page}{%
\nointerlineskip
\begin{adjustbox}{width=\paperwidth,center}
\begin{tikzpicture}
\useasboundingbox (0,0) rectangle (\paperwidth,\paperheight);
\fill[color=white] (0,0) rectangle (\paperwidth,\paperheight);
\fill[color=MedianOrange] (0,6) rectangle (1.5, 7);
\fill[color=MedianLightBlue] (1.6, 6) rectangle (\paperwidth, 7);
\node[text width=0.8\paperwidth,right] at (1.8,6.5) {
\begin{beamercolorbox}{section page}
\insertsectionhead
\end{beamercolorbox}
};
\end{tikzpicture}
\end{adjustbox}
}
\setbeamertemplate{frametitle}
{
\vskip0.3cm
\begin{beamercolorbox}{frametitle}
\insertframetitle
\end{beamercolorbox}
}
\setbeamertemplate{items}[square]
\setbeamertemplate{sections/subsections in toc}[square]
\author{Author Name}
\title{Quite A Long Title For A Simple Beamer Presentation}
\date{\today}
\AtBeginSection{\frame{\sectionpage}}
\begin{document}
\frame{\titlepage}
\section{Introduction}
\begin{frame}{My presentation is about\ldots}
\begin{itemize}
\item Some stuff
\item And some other stuff
\end{itemize}
\end{frame}
\end{document}