![beamerframe 键:设置字体、颜色和其他特定于框架的样式](https://linux22.com/image/453869/beamerframe%20%E9%94%AE%EF%BC%9A%E8%AE%BE%E7%BD%AE%E5%AD%97%E4%BD%93%E3%80%81%E9%A2%9C%E8%89%B2%E5%92%8C%E5%85%B6%E4%BB%96%E7%89%B9%E5%AE%9A%E4%BA%8E%E6%A1%86%E6%9E%B6%E7%9A%84%E6%A0%B7%E5%BC%8F.png)
我的目标是为带有以下标签的特定框架分配自定义样式:[想要]关键,特别是字体系列、字体颜色和背景颜色。我能够将背景颜色与关键联系起来,但在尝试对字体进行同样的操作时,成功率较低。我想要的结果是能够只写:
\begin{frame}[fancy]
\frametitle{fancy title with fancy font and colors}
fancy background, fonts, and colors
\end{frame}
我目前的解决方法是定义自定义框架和自定义框架标题命令(fancyframe 和 fancyframetitle),但我更喜欢使用简单的 fancy 标签来控制样式(更容易打开和关闭)。
以下代码尝试将 beamer 代码中的部分内容整合在一起。背景颜色似乎可以正常工作,但字体和颜色要么漏掉,要么没有应用到正确的位置。输出结果一团糟。
\documentclass[xcolor={usenames,dvipsnames}]{beamer}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[border shrink=2mm]
% default options for presentation
\mode<presentation>
{
\setbeamercolor{frametitle}{bg=white,fg=Green}
\setbeamertemplate{itemize item}{$-$}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[pagenumber,split]
}
% define some special font for fancy frames
\usepackage{fontspec,unicode-math}
\newfontfamily\myfontfamily{augie}
% set default frame style
\defbeamertemplate*{background canvas}{mydefault}
{%
\ifbeamercolorempty[bg]{background canvas}{}{\color{bg}\vrule width\paperwidth height\paperheight}% beamer default
}
% reset the default frame styles... doing this wrong?
\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background canvas}[mydefault]%
\usebeamerfont{normal text}
}
% set background color for fancy frames
\defbeamertemplate*{background canvas}{fancy}
{%
\color{lightgray!50}\vrule width\paperwidth height\paperheight% background color added
}
% define the fancy key
\makeatletter
\define@key{beamerframe}{fancy}[true]{%
\setbeamercovered{invisible}
\setbeamertemplate{background canvas}[fancy]
\setbeamerfont{normal text}{family={\myfontfamily}}% leaks
\setbeamertemplate{itemize item}{$\blacktriangleright$}% leaks
\setbeamertemplate{frametitle}{\color{Red}\textbf{\insertframetitle}}% leaks
}
\makeatother
% workaround: custom frame title | likewise could make custom frames, but don't want to...
\newcommand{\fancyframetitle}[1]{\textcolor{NavyBlue}{\myfontfamily\Large#1}\vspace{0.05\paperheight}\par}
\begin{document}
\begin{frame}
\frametitle{Normal Frame (Green Title, Normal Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\begin{frame}[fancy]
\frametitle{Fancy Frame (Red Title, Fancy Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Normal Frame (Green Title, Normal Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\begin{frame}[fancy]
\fancyframetitle{Fancy Frame (Blue Title, Fancy Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\end{document}
实验失败的结果:样式泄露或未在预期的地方应用。
答案1
解决方案与https://tex.stackexchange.com/a/174213/36296
您必须在每一帧之前撤消所有特殊设置(并注意设置/使用的顺序):
% !TeX TS-program = lualatex
\documentclass[xcolor={usenames,dvipsnames}]{beamer}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[border shrink=2mm]
% default options for presentation
\mode<presentation>
{
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[pagenumber,split]
}
% define some special font for fancy frames
\usepackage{fontspec,unicode-math}
\newfontfamily\myfontfamily{augie}
% reset the default frame styles
\BeforeBeginEnvironment{frame}{%
\setbeamercolor{background canvas}{bg=white}%
\setbeamerfont{frametitle}{family=\sffamily,series=\normalfont}
\setbeamercolor{frametitle}{bg=white,fg=Green}
\setbeamertemplate{itemize item}{$-$}
\setbeamerfont{normal text}{family=\sffamily}
\usebeamerfont{normal text}
}
% define the fancy key
\makeatletter
\define@key{beamerframe}{fancy}[true]{%
\setbeamercolor{background canvas}{bg=lightgray!50}%
\setbeamercovered{invisible}
\setbeamertemplate{background canvas}[fancy]
\setbeamerfont{frametitle}{family={\myfontfamily},series=\bfseries}
\setbeamercolor{frametitle}{bg=lightgray!50,fg=red}
\setbeamertemplate{itemize item}{$\blacktriangleright$}
\setbeamerfont{normal text}{family={\myfontfamily}}
\usebeamerfont{normal text}
}
\makeatother
% special title for one-off use
\newcommand{\fancyframetitle}[1]{\textcolor{NavyBlue}{\myfontfamily\Large#1}\vspace{0.05\paperheight}\par}
\begin{document}
\begin{frame}
\frametitle{Normal Frame (Green Title, Normal Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\begin{frame}[fancy]
\frametitle{Fancy Frame (Red Title, Fancy Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Normal Frame (Green Title, Normal Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\begin{frame}[fancy]
\fancyframetitle{Fancy Frame (Blue Title, Fancy Font)}
\lipsum[11]
\begin{itemize}
\item \lipsum[11]
\end{itemize}
\end{frame}
\end{document}