我目前正在尝试在 Beamer 中编写以下图像。到目前为止,我得到了这三张图像beamercolorbox
,但我无法获得阴影背景。
这是我想要的方面:
\documentclass[xcolor=dvipsnames,14pt]{beamer}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\usetikzlibrary{calc}
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\setlength\parskip{0.75em}
\setlength\parindent{0pt}
\setbeamersize{text margin left=3mm,text margin right=3mm}{}
\setbeamerfont{section in head/foot}{size=\scriptsize}
\setbeamerfont{subsection in head/foot}{size=\scriptsize}
\setbeamerfont{date in head/foot}{size=\scriptsize}
\setbeamercolor{section in head/foot}{fg=black,bg=gray}
\setbeamercolor{subsection in head/foot}{fg=black,bg=gray}
\setbeamercolor{date in head/foot}{fg=black,bg=gray}
\setbeamertemplate{headline}{
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}%
\end{beamercolorbox}%
}\vskip0pt}
\begin{document}
\section{Section title}
\subsection{Subsection title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}
\end{document}
解决方案:实际上,我只需将阴影放在 hbox 中并使用\hskip
和\vskip
。以下是解决方案:
\setbeamertemplate{headline}{
\leavevmode%
\hskip-1mm\hbox{%
\pgfdeclarehorizontalshading{beamer@topshade}{4ex}{
color(0mm)=(headsectionback1);
color(54mm)=(headsectionback2);
color(54.001mm)=(headsubsectionback1);
color(119mm)=(headsubsectionback2);
color(119.001mm)=(headpageback);
color(128mm)=(headpageback)}
\pgfuseshading{beamer@topshade}
}\hskip-128mm\vskip-4ex%
\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}
\end{beamercolorbox}%
}\vskip0pt%
}
答案1
让我们假设所谓的阴影背景放置在headline
模板中。
在这种情况下,答案提供了一种插入垂直阴影背景或简单背景的方法。
简单背景
\documentclass[xcolor=dvipsnames,14pt]{beamer}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\usetikzlibrary{calc}
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\setlength\parskip{0.75em}
\setlength\parindent{0pt}
\setbeamersize{text margin left=3mm,text margin right=3mm}{}
\setbeamerfont{section in head/foot}{size=\scriptsize}
\setbeamerfont{subsection in head/foot}{size=\scriptsize}
\setbeamerfont{date in head/foot}{size=\scriptsize}
\setbeamercolor{section in head/foot}{fg=black,bg=gray}
\setbeamercolor{subsection in head/foot}{fg=black,bg=gray}
\setbeamercolor{date in head/foot}{fg=black,bg=gray}
% uniform color
\setbeamercolor{shadedhead}{bg=blue}
\setbeamertemplate{headline}{
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}%
\end{beamercolorbox}%
}\vskip0pt
\leavevmode\hbox{%
% uniform
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{shadedhead}%
\end{beamercolorbox}%
}\vskip0pt
}
\begin{document}
\section{Section title}
\subsection{Subsection title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}
\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}
\subsection{Subsection second title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}
\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}
\end{document}
背景已通过以下方式插入:
\leavevmode\hbox{%
% uniform
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{shadedhead}%
\end{beamercolorbox}%
}
并且可以通过改变以下内容来修改颜色定义:
\setbeamercolor{shadedhead}{bg=blue}
您可以在环境选项中调整尺寸beamercolorbox
。
结果的两帧:
带垂直阴影的背景
我们首先定义阴影:
% Shade definition
\pgfdeclareverticalshading{mytopshade}{\paperwidth}{%
color(0pt)=(gray!40);
color(10pt)=(gray)}
您可以在 pgfmanual(也相关)中找到有关可能的阴影的更多信息如何创建球形阴影并手动自定义 3D 照明?)。
现在我们在模板中应用此阴影headline
:
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{}%
\begin{pgfpicture}{0pt}{0pt}{\paperwidth}{3ex}
\pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{3ex}}
\pgfusepath{clip}
\pgftext[left,base]{\pgfuseshading{mytopshade}}
\end{pgfpicture}
\end{beamercolorbox}%
}
整个代码:
\documentclass[xcolor=dvipsnames,14pt]{beamer}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\usetikzlibrary{calc}
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\setlength\parskip{0.75em}
\setlength\parindent{0pt}
\setbeamersize{text margin left=3mm,text margin right=3mm}{}
\setbeamerfont{section in head/foot}{size=\scriptsize}
\setbeamerfont{subsection in head/foot}{size=\scriptsize}
\setbeamerfont{date in head/foot}{size=\scriptsize}
\setbeamercolor{section in head/foot}{fg=black,bg=gray}
\setbeamercolor{subsection in head/foot}{fg=black,bg=gray}
\setbeamercolor{date in head/foot}{fg=black,bg=gray}
% Shade definition
\pgfdeclareverticalshading{mytopshade}{\paperwidth}{%
color(0pt)=(gray!40);
color(10pt)=(gray)}
\setbeamertemplate{headline}{
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}%
\end{beamercolorbox}%
}\vskip0pt
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{}%
\begin{pgfpicture}{0pt}{0pt}{\paperwidth}{3ex}
\pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{3ex}}
\pgfusepath{clip}
\pgftext[left,base]{\pgfuseshading{mytopshade}}
\end{pgfpicture}
\end{beamercolorbox}%
}\vskip0pt
}
\begin{document}
\section{Section title}
\subsection{Subsection title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}
\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}
\subsection{Subsection second title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}
\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}
\end{document}
现在,上一个示例的相同帧显示如下: