1

How to get a horizontally shaded title in a beamer presentation?

There are several post to do this for block titles or frame titles but I did not find anything for the title of the title page.


Edit: I am using the Madrid theme, here is a MWE of my current configuration:

\documentclass[xcolor={dvipsnames,svgnames,table},10pt]{beamer}

\usepackage[T1]{fontenc}

\colorlet{titleleft}{Red}
\colorlet{titleright}{Green}

\setbeamercolor*{frametitle}{fg=white}

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

\defbeamertemplate*{frametitle}{horizontal shading}
{%
  \nointerlineskip%
  \vskip+3pt%
  \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

\setbeamertemplate{frametitle}[rounded corners]

\title{TEST}

\begin{document}

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

\begin{frame}{$\hspace{5em}$\textbf{Test}}
 a Test frame
\end{frame}

\end{document}

We can clearly see that the title isn't shaded unlike the frame title.

  • Can you add a MWE? Which theme are you using? – user36296 May 16 '16 at 19:39
  • @samcarter I am using the Madrid theme. – Raoul722 May 16 '16 at 22:41
  • It isn't really clear to me what you want. You can add a shaded block to the title page like the one at the top of the test frame. Since title pages don't have frame titles, it will be empty, but it will be there. Or you might want a shaded block in a different place in the frame for this page. It is not at all clear. And it doesn't help that your MWE features neither a title page nor a title! – cfr May 17 '16 at 2:05
  • @cfr I could add a shaded frame title but it would not be centered like the \titlecommand. I would like to shade the block produced by \title. Is it possible? – Raoul722 May 17 '16 at 6:50
2

There you go:

\documentclass[xcolor={dvipsnames,svgnames,table},10pt]{beamer}

\usepackage[T1]{fontenc}

\colorlet{titleleft}{Red}
\colorlet{titleright}{Green}

\setbeamercolor*{frametitle}{fg=white}

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

\defbeamertemplate*{frametitle}{horizontal shading}
{%
  \nointerlineskip%
  \vskip+3pt%
  \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%
          \hskip5em
          \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
}

\setbeamertemplate{title page}
{
    \vbox{}
    \vfill
    \begingroup
    \centering
  \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{%
            \hskip24bp              
                \begin{beamercolorbox}[sep=8pt,center,colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow]{title}
                \usebeamerfont{title}\inserttitle\par%
                \ifx\insertsubtitle\@empty%
                \else%
                \vskip0.25em%
                {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
                \fi%     
            \end{beamercolorbox}%
                }
            \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    
    \vskip1em\par
    \begin{beamercolorbox}[sep=8pt,center,colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow]{author}
        \usebeamerfont{author}\insertauthor
    \end{beamercolorbox}
    \begin{beamercolorbox}[sep=8pt,center,colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow]{institute}
        \usebeamerfont{institute}\insertinstitute
    \end{beamercolorbox}
    \begin{beamercolorbox}[sep=8pt,center,colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow]{date}
        \usebeamerfont{date}\insertdate
    \end{beamercolorbox}\vskip0.5em
    {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par}
    \endgroup
    \vfill
}
\makeatother

\setbeamerfont{frametitle}{series=\bfseries}
\setbeamerfont{title}{series=\bfseries}
\setbeamercolor{title}{fg=white}

\title{TEST}

\begin{document}

\begin{frame}[plain]
    \titlepage
\end{frame}

\begin{frame}{Test}
 a Test frame
\end{frame}

\end{document}

enter image description here

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.