如何为Beamer普通内容幻灯片创建并切换不同布局?
为Beamer普通内容幻灯片创建不同布局的方法
核心结论
- 完全可以用类似标题页的方式为普通内容幻灯片创建并切换不同布局
- 内容幻灯片的核心关联关键词:
frame、background、headline/footline、page style
具体实现步骤
1. 定义内容幻灯片的背景模板
和标题页的\defbeamertemplate{background}用法一致,为不同布局创建专属背景:
% 横向内容页背景 \defbeamertemplate{background}{content_horizontal}{ \includegraphics[width=\paperwidth]{horizontal-content-bg.png} } % 纵向内容页背景 \defbeamertemplate{background}{content_vertical}{ \color{blue!10}\vfill\hfill\includegraphics[height=\paperheight]{vertical-content-bg.png}\hfill\vfill }
2. 绑定布局元素的页样式
用\def\ps@xxx定义页样式,把背景、页眉、页脚等元素绑定在一起:
% 横向内容页的页样式 \def\ps@content@horizontal{% \setbeamertemplate{background}[content_horizontal] \setbeamertemplate{headline}{% 自定义页眉 \vspace{8pt}\hfill\insertshorttitle\hfill\insertframenumber/\inserttotalframenumber\vspace{8pt} } \setbeamertemplate{footline}{} % 隐藏页脚 } % 纵向内容页的页样式 \def\ps@content@vertical{% \setbeamertemplate{background}[content_vertical] \setbeamertemplate{headline}{} % 隐藏页眉 \setbeamertemplate{footline}{% 自定义页脚 \vspace{8pt}\centering\insertauthor\vspace{8pt} } }
3. 创建快速切换布局的命令(可选)
为了简化调用,定义一个命令来快速切换布局:
\usepackage{ifthen} % 需要引入ifthen包处理条件判断 \newcommand{\switchContentLayout}[1]{% \ifthenelse{\equal{#1}{horizontal}} { \thispagestyle{content@horizontal} }{} \ifthenelse{\equal{#1}{vertical}} { \thispagestyle{content@vertical} }{} }
4. 在文档中调用布局
在需要的幻灯片中切换布局:
% 横向布局的内容幻灯片 \begin{frame}{横向布局演示} \switchContentLayout{horizontal} 这是使用横向背景和自定义页眉的内容页。 \end{frame} % 纵向布局的内容幻灯片 \begin{frame}{纵向布局演示} \switchContentLayout{vertical} 这是使用纵向背景和自定义页脚的内容页。 \end{frame}
全局设置布局
如果想让所有内容幻灯片默认使用某一布局,在文档开头添加:
\pagestyle{content@horizontal}
补充说明
- 内容幻灯片的默认页样式是
default(带页眉页脚)或plain(无页眉页脚),自定义页样式会覆盖这些默认设置 - 除了背景、页眉页脚,还可以在页样式中自定义
sidebar、navigation symbols等其他元素
内容的提问来源于stack exchange,提问作者mrCarnivore
相关产品推荐
相关产品推荐

