3

This question is similar to How can I have a horizontally shaded block title in beamer?. I want to achieve the horizontal shading effect in the frametitle and when I use

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

I get compilation errors:

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

Vertical shading seems to work just fine.

  • Which theme are you using? Can you please add a little document to your question showing the relevant settings used? In particular, I'd like to see the settings you use when you say that frametitle works with vertical shading. – Gonzalo Medina Feb 5 '15 at 16:34
6

The easiest way is to use the shadow outer theme and \pgfdeclarehorizontalshading to customize frametitleshade, as the following simple example illustrates:

\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}

The result:

enter image description here

This, however, might not be the most convenient option since the shadow theme also includes a shadow below the template (which might produce undesired effects for some themes (e.g., those using a sidebar)) and the theme also redefines the headline (and this could also not be desired).

A more personal, yet involved, solution would be to define your own frametitle template to the shading; here's an example document showing how this could be done:

\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}

The result:

enter image description here

Refer to the PGF manual (Section 110.2 Declaring Shadings) to customize the shading; one could, for example say

\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)}

And the result in my last example would be:

enter image description here

  • The first one works but to use the shadow theme, I cannot use my theme. The second solution worked just fine, I just adjusted it and put it in my .sty file. Thanks for your answer! – Evangelos Bempelis Feb 5 '15 at 17:33
  • One more question, is there a way to adjust the gradient, i.e. the points at which the colors change? – Evangelos Bempelis Feb 5 '15 at 17:37
  • @VagelisBebelis Sure! Please see my updated answer (the comments and example at the bottom). – Gonzalo Medina Feb 5 '15 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.