1

Starting from Tree outer theme, I would like to add horizontal shading to each of the headlines line (as in Shadow outer theme), but a different shading for each line. Say, for a more striking example, blue to orange for document's title, purple to green for section, red to yellow for subsection, and black to gray for the frame title.

Taking inspiration from the answer given to a previous question of mine (and pasting the chunk on frame title from the Shadow theme file):

Tweaking infolines outer theme with horizontal shading

I typed the following code:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{shadings}

\useoutertheme{shadow}
\useoutertheme{tree}
\usecolortheme{whale}
\usefonttheme{professionalfonts}

\setbeamercolor{title in head/foot}{fg=white,bg=}
\setbeamercolor{section in head/foot}{fg=white,bg=}
\setbeamercolor{subsection in head/foot}{fg=white,bg=}
\setbeamercolor{frametitle}{fg=white,bg=}

\pgfdeclarehorizontalshading{beamer@titleshade}{\paperheight}{
    color(0pt)=(blue);
    color(\paperwidth)=(orange)
}

\pgfdeclarehorizontalshading{beamer@sectionshade}{\paperheight}{
    color(0pt)=(purple);
    color(\paperwidth)=(green)
}

\pgfdeclarehorizontalshading{beamer@subsectionshade}{\paperheight}{
    color(0pt)=(red);
    color(\paperwidth)=(yellow)
}

\pgfdeclarehorizontalshading{beamer@frametitleshade}{\paperheight}{
    color(0pt)=(black);
    color(\paperwidth)=(gray)
}

\makeatletter
\setbeamertemplate{headline}
{
    \leavevmode%
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
    \end{beamercolorbox}
    \setbox\beamer@tempbox=\hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
            leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
            \usebeamerfont{title in head/foot}\insertshorttitle
        \end{beamercolorbox}
    }%
    \beamer@tempdim=\ht\beamer@tempbox%
    \advance\beamer@tempdim by 4pt%
    \vskip-\beamer@tempdim%
    \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{20pt}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
        \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@titleshade}}
    \end{pgfpicture}
    \vskip-\beamer@tempdim%
    \box\beamer@tempbox%    
    \vskip0pt%
    \setbox\beamer@tempbox=\hbox{%  
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
            leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
            \usebeamerfont{section in head/foot}%
            \ifbeamer@tree@showhooks
            \setbox\beamer@tempbox=\hbox{\insertsectionhead}%
            \ifdim\wd\beamer@tempbox>1pt%
            \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
            \hskip1pt%
            \fi%
            \else%  
            \hskip6pt%
            \fi%
            \insertsectionhead
        \end{beamercolorbox}
    }
    \beamer@tempdim=\ht\beamer@tempbox%
    \advance\beamer@tempdim by 4pt%
    \vskip-\beamer@tempdim%
    \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{20pt}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
        \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@sectionshade}}
    \end{pgfpicture}
    \vskip-\beamer@tempdim%
    \box\beamer@tempbox%    
    \vskip0pt%
    \setbox\beamer@tempbox=\hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
            leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
            \usebeamerfont{subsection in head/foot}%
            \ifbeamer@tree@showhooks
            \setbox\beamer@tempbox=\hbox{\insertsubsectionhead}%
            \ifdim\wd\beamer@tempbox>1pt%
            \hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
            \hskip1pt%
            \fi%
            \else%  
            \hskip12pt%
            \fi%
            \insertsubsectionhead
        \end{beamercolorbox}
        \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
        \end{beamercolorbox}
    }
    \beamer@tempdim=\ht\beamer@tempbox%
    \advance\beamer@tempdim by 4pt%
    \vskip-\beamer@tempdim%
    \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{20pt}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}} \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@subsectionshade}}
    \end{pgfpicture}
    \vskip-\beamer@tempdim%
    \box\beamer@tempbox%    
    \vskip0pt%
}

\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]{\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%
    }%
    \nointerlineskip
    \vskip-0.2pt
    \hbox to\textwidth{\hskip-\Gm@lmargin\pgfuseshading{beamer@topshade}\hskip-\Gm@rmargin}
    \vskip-2pt
}

\makeatother

\title{Title}
\author{Author}
\institute{Institute}
\date{Date}

\begin{document}

\section{Title of Section 1}
\subsection{Title of Subsection 1-1}

\begin{frame}
\frametitle{Frame Title}
Some text.
\end{frame}

\end{document}

Here's the result: enter image description here

It's a good start, however notice that the height of the headlines is inconsistent. In particular, the subsection line is "cut short" just below its text. Also, there's that blank space below navigation symbols, I don't know where it comes from.

I surmise it has to do with the spacing below or above the shading pictures, or the beamer color boxes, but I don't know how to fine tune it...

Thanks in advance for your advice!

  • 1
    You are only distracting the audience or the reader. Also as a colorblind those transitions are just annoying :-) – percusse Nov 19 '17 at 19:37
  • I know this template is obnoxiously ugly :-) I plan to use shades of only two colors in my final work. I picked colors that are very different from one another in this training example just to hunt for glitches. If one shading is out of place, I immediately spot it. – Magean Nov 19 '17 at 19:47
1

You can control the depth of the colour boxes with the parameter dp=1.125ex. To get more depth, increase it to e.g. 1.5.

As for the space between the navigation symbols and the bottom of the frame, this is your footline. Despite the fact that you set the colours to white/transparent it is still there. If you want to remove it: \setbeamertemplate{footline}{}

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{shadings}

\useoutertheme{shadow}
\useoutertheme{tree}
\usecolortheme{whale}
\usefonttheme{professionalfonts}

\setbeamercolor{title in head/foot}{fg=white,bg=}
\setbeamercolor{section in head/foot}{fg=white,bg=}
\setbeamercolor{subsection in head/foot}{fg=white,bg=}
\setbeamercolor{frametitle}{fg=white,bg=}

\pgfdeclarehorizontalshading{beamer@titleshade}{\paperheight}{
    color(0pt)=(blue);
    color(\paperwidth)=(orange)
}

\pgfdeclarehorizontalshading{beamer@sectionshade}{\paperheight}{
    color(0pt)=(purple);
    color(\paperwidth)=(green)
}

\pgfdeclarehorizontalshading{beamer@subsectionshade}{\paperheight}{
    color(0pt)=(red);
    color(\paperwidth)=(yellow)
}

\pgfdeclarehorizontalshading{beamer@frametitleshade}{\paperheight}{
    color(0pt)=(black);
    color(\paperwidth)=(gray)
}

\makeatletter
\setbeamertemplate{headline}
{
    \leavevmode%
    \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
    \end{beamercolorbox}
    \setbox\beamer@tempbox=\hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.5ex,%
            leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
            \usebeamerfont{title in head/foot}\insertshorttitle
        \end{beamercolorbox}
    }%
    \beamer@tempdim=\ht\beamer@tempbox%
    \advance\beamer@tempdim by 4pt%
    \vskip-\beamer@tempdim%
    \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{20pt}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
        \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@titleshade}}
    \end{pgfpicture}
    \vskip-\beamer@tempdim%
    \box\beamer@tempbox%    
    \vskip0pt%
    \setbox\beamer@tempbox=\hbox{%  
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.5ex,%
            leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
            \usebeamerfont{section in head/foot}%
            \ifbeamer@tree@showhooks
            \setbox\beamer@tempbox=\hbox{\insertsectionhead}%
            \ifdim\wd\beamer@tempbox>1pt%
            \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
            \hskip1pt%
            \fi%
            \else%  
            \hskip6pt%
            \fi%
            \insertsectionhead
        \end{beamercolorbox}
    }
    \beamer@tempdim=\ht\beamer@tempbox%
    \advance\beamer@tempdim by 4pt%
    \vskip-\beamer@tempdim%
    \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{20pt}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
        \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@sectionshade}}
    \end{pgfpicture}
    \vskip-\beamer@tempdim%
    \box\beamer@tempbox%    
    \vskip0pt%
    \setbox\beamer@tempbox=\hbox{%
        \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.5ex,%
            leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
            \usebeamerfont{subsection in head/foot}%
            \ifbeamer@tree@showhooks
            \setbox\beamer@tempbox=\hbox{\insertsubsectionhead}%
            \ifdim\wd\beamer@tempbox>1pt%
            \hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
            \hskip1pt%
            \fi%
            \else%  
            \hskip12pt%
            \fi%
            \insertsubsectionhead
        \end{beamercolorbox}
        \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{lower separation line head}
        \end{beamercolorbox}
    }
    \beamer@tempdim=\ht\beamer@tempbox%
    \advance\beamer@tempdim by 4pt%
    \vskip-\beamer@tempdim%
    \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{20pt}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}} \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@subsectionshade}}
    \end{pgfpicture}
    \vskip-\beamer@tempdim%
    \box\beamer@tempbox%    
    \vskip0pt%
}

\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]{\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%
    }%
    \nointerlineskip
    \vskip-0.2pt
    \hbox to\textwidth{\hskip-\Gm@lmargin\pgfuseshading{beamer@topshade}\hskip-\Gm@rmargin}
    \vskip-2pt
}

\makeatother

\setbeamertemplate{footline}{}

\title{Title}
\author{Author}
\institute{Institute}
\date{Date}

\begin{document}

\section{Title of Section 1}
\subsection{Title of Subsection 1-1}

\begin{frame}
\frametitle{Frame Title}
Some text.
\end{frame}

\end{document}

enter image description here

  • Thanks, I'll toy around with that parameter. I also improved the result by adjusting the recurring \vskip0pt line and replacing 0 with something else (2.5 worked fine). – Magean Nov 19 '17 at 20:31

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.