1

I would like to create a vertical colour gradient in the background of the frametitle element in the beamer package. I have succeeded in doing this for the whole background of the frames (using %\setbeamertemplate{background canvas} [vertical shading][bottom=blue!15,top=green,midpoint=.1]). Is there anything similar for the background of frametitles? Thanks!

\documentclass{beamer}
\usetheme[height=1cm]{rochester}
\setbeamertemplate{frametitle}[default][center]

\title{Presentation}
\subtitle{}
\author{}
\institute{}
\date{\today} 

\begin{document}

\begin{frame}
    \titlepage{}
\end{frame}

\begin{frame}
    \frametitle{Frametitle which should have vertical shading}
\end{frame}

\end{document}
2

1 Answer 1

1
\documentclass{beamer}
\usetheme[height=0cm]{Rochester}

\setbeamercolor{frametitle}{parent=subsection in head/foot}
\setbeamercolor{frametitle right}{bg=green}

\makeatletter
\pgfdeclareverticalshading[frametitle.bg,frametitle right.bg]{beamer@frametitleshade}{\paperwidth}{%
    color(0pt)=(frametitle right.bg);
    color(.15\paperheight)=(frametitle.bg)}

\AtBeginDocument{
    \pgfdeclareverticalshading{beamer@topshade}{\paperwidth}{%
        color(0pt)=(bg);
        color(4pt)=(black!50!bg)}
}

\setbeamertemplate{frametitle}
{%
    \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][.15\paperheight][c]{\paperwidth}%
                    \vbox{}\vskip-.75ex%
                    \leftskip0.3cm%
                    \rightskip0.3cm plus1fil\leavevmode
                    \hfill\insertframetitle\hfill%
                    \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%
        }%
        \nointerlineskip
        \vskip-0.2pt
        \hbox to\textwidth{\hskip-\Gm@lmargin\pgfuseshading{beamer@topshade}\hskip-\Gm@rmargin}
        \vskip-2pt
    }
\makeatother


\title{Presentation}
\subtitle{}
\author{}
\institute{}
\date{\today} 

\begin{document}

\begin{frame}
    \titlepage{}
\end{frame}

\section{text}
\subsection{wl}
\begin{frame}
    \frametitle{Frametitle which should have vertical shading}
\end{frame}

\end{document}

enter image description here

5
  • Just a quick follow-up question for samcarter: Your solution works well; the only thing I have done is set the blue margin to zero using \usetheme[height=1cm]{rochester}, as I only want the gradient. All I would need to
    – Thomas
    Commented Oct 24, 2016 at 9:52
  • Just a quick follow-up question for samcarter: Your solution works well; the only thing I have done is set the blue margin to zero using \usetheme[height=1cm]{rochester}, as I only want the gradient. My question would be: How can you increase the height of the gradient? My pure TeX skills are quite poor, and I haven't succeeded in doing that despite fiddling around with all sorts of tags in the \frametitle redefinition. Thanks in advance!
    – Thomas
    Commented Oct 24, 2016 at 9:53
  • @Thomas Two things to do: 1) What should the total height of the frametitle be? Where should the text be located? 2) Go over your old questions and consider accepting the answer that solved your problems. Commented Oct 24, 2016 at 11:55
  • Sorry for delaying the acceptance of your answer – I have accepted in now. The height of the frametitle should be 15% of \paperheight. Is this helpful, or would you need an absolute measure? The text should be centered both vertically and horizontally.
    – Thomas
    Commented Oct 31, 2016 at 7:50
  • @Thomas see the edit. Is this what you are looking for? And thanks for accepting my answer. For the whole site it be helpful if you do the same with your older questions, too. See meta.stackexchange.com/questions/156170/… Commented Oct 31, 2016 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .