我怎样才能在投影仪中得到水平阴影的框架标题?

我怎样才能在投影仪中得到水平阴影的框架标题?

这个问题类似于我怎样才能在投影仪中获得水平阴影块标题?frametitle。我想在和中使用时实现水平阴影效果

\setbeamertemplate{frametitle}[horizontal shading]
[left=red, right=white]

我收到编译错误:

LaTeX Error: Missing \begin{document}. [[]

垂直阴影似乎工作得很好。

答案1

最简单的方法是使用shadow外部主题并\pgfdeclarehorizontalshading自定义frametitleshade,如下面的简单示例所示:

\documentclass{beamer}
\useoutertheme{shadow}
\usepackage{tikz}
\usetikzlibrary{shadings}

\colorlet{titleleft}{red!70!black}
\colorlet{titleright}{white}

\setbeamercolor*{frametitle}{fg=white}

\makeatletter
\pgfdeclarehorizontalshading[titleleft,titleright]{beamer@frametitleshade}{\paperheight}{%
  color(0pt)=(titleleft);
  color(\paperwidth)=(titleright)}
\makeatother

\begin{document}

\begin{frame}
\frametitle{Test title}
Test frame
\end{frame}

\end{document}

结果:

在此处输入图片描述

然而,这可能不是最方便的选择,因为shadow主题还在模板下方包含阴影(这可能会对某些主题(例如,使用侧边栏的主题)产生不良效果)并且主题还重新定义了标题(这也可能不是想要的)。

一个更加个性化但更复杂的解决方案是定义您自己的frametitle阴影模板;这里有一个示例文档,展示了如何做到这一点:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shadings}

\colorlet{titleleft}{red!70!black}
\colorlet{titleright}{white}

\setbeamercolor*{frametitle}{fg=white}

\makeatletter
\pgfdeclarehorizontalshading[titleleft,titleright]{beamer@frametitleshade}{\paperheight}{%
  color(0pt)=(titleleft);
  color(\paperwidth)=(titleright)}

\defbeamertemplate*{frametitle}{horizontal shading}
{%
  \nointerlineskip%
  %\vskip-2pt%
  \hbox{\leavevmode
    \advance\beamer@leftmargin by -12bp%
    \advance\beamer@rightmargin by -12bp%
    \beamer@tempdim=\textwidth%
    \advance\beamer@tempdim by \beamer@leftmargin%
    \advance\beamer@tempdim by \beamer@rightmargin%
    \hskip-\Gm@lmargin\hbox{%
      \setbox\beamer@tempbox=\hbox{\begin{minipage}[b]{\paperwidth}%
          \vbox{}\vskip-.75ex%
          \leftskip0.3cm%
          \rightskip0.3cm plus1fil\leavevmode
          \insertframetitle%
          \ifx\insertframesubtitle\@empty%
            \strut\par%
          \else
            \par{\usebeamerfont*{framesubtitle}{\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}\strut\par}%
          \fi%
          \nointerlineskip
          \vbox{}%
          \end{minipage}}%
      \beamer@tempdim=\ht\beamer@tempbox%
      \advance\beamer@tempdim by 2pt%
      \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{\beamer@tempdim}
        \usebeamercolor{frametitle right}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
        \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@frametitleshade}}
      \end{pgfpicture}
      \hskip-\paperwidth%
      \box\beamer@tempbox%
    }%
    \hskip-\Gm@rmargin%
  }%
    \vskip-2pt
}
\makeatother

\begin{document}

\begin{frame}
\frametitle{Test title}
Test frame
\end{frame}

\end{document}

结果:

在此处输入图片描述

请参阅PGF手册(第110.2 声明阴影)来自定义阴影;例如可以说

\colorlet{titleleft}{red!70!black}
\colorlet{titleonequarter}{orange!80!blue!30}
\colorlet{titlethreequarter}{blue!80!orange!30}
\colorlet{titleright}{green}
\pgfdeclarehorizontalshading[titleleft,titleonequarter,titlethreequarter,titleright]{beamer@frametitleshade}{\paperheight}{
  color(0pt)=(titleleft);
  color(0.25\paperwidth)=(titleonequarter);
  color(0.75\paperwidth)=(titlethreequarter);
  color(\paperwidth)=(titleright)}

我最后一个例子的结果是:

在此处输入图片描述

相关内容