# How can I have a horizontally shaded frametitle in beamer?

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

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

\documentclass{beamer}
\usepackage{tikz}

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

\setbeamercolor*{frametitle}{fg=white}

\makeatletter
color(0pt)=(titleleft);
color(\paperwidth)=(titleright)}
\makeatother

\begin{document}

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

\end{document}


The result:

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}

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

\setbeamercolor*{frametitle}{fg=white}

\makeatletter
color(0pt)=(titleleft);
color(\paperwidth)=(titleright)}

{%
\nointerlineskip%
%\vskip-2pt%
\hbox{\leavevmode
\beamer@tempdim=\textwidth%
\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%
\begin{pgfpicture}{0pt}{0pt}{\paperwidth}{\beamer@tempdim}
\usebeamercolor{frametitle right}
\pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
\pgfusepath{clip}
\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:

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

• 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