2

I am currently trying to code in beamer the following image. So far I got the three beamercolorbox but I can't get the shaded background.

Here is the aspect I want:

enter image description here

\documentclass[xcolor=dvipsnames,14pt]{beamer}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\usetikzlibrary{calc}
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\setlength\parskip{0.75em}
\setlength\parindent{0pt}
\setbeamersize{text margin left=3mm,text margin right=3mm}{}
\setbeamerfont{section in head/foot}{size=\scriptsize}
\setbeamerfont{subsection in head/foot}{size=\scriptsize}
\setbeamerfont{date in head/foot}{size=\scriptsize}
\setbeamercolor{section in head/foot}{fg=black,bg=gray}
\setbeamercolor{subsection in head/foot}{fg=black,bg=gray}
\setbeamercolor{date in head/foot}{fg=black,bg=gray}
\setbeamertemplate{headline}{
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}%
\end{beamercolorbox}%
}\vskip0pt}

\begin{document}
\section{Section title}
\subsection{Subsection title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}
\end{document}

Solution: In fact, I just had to put the shadings in a hbox and use \hskip and \vskip. Here is the solution:

\setbeamertemplate{headline}{
\leavevmode%
\hskip-1mm\hbox{%
\pgfdeclarehorizontalshading{beamer@topshade}{4ex}{
color(0mm)=(headsectionback1); 
color(54mm)=(headsectionback2);
color(54.001mm)=(headsubsectionback1); 
color(119mm)=(headsubsectionback2);
color(119.001mm)=(headpageback); 
color(128mm)=(headpageback)}
\pgfuseshading{beamer@topshade}
}\hskip-128mm\vskip-4ex%
\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}
\end{beamercolorbox}%
}\vskip0pt%
}
2
  • Welcome to TeX.SX. The shaded background must be still in the headline or not? Which kind of shading you want to insert? Jul 2, 2012 at 13:48
  • Welcome to TEX.SX! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you.
    – azetina
    Jul 2, 2012 at 14:03

1 Answer 1

3

Let's assume the so called shaded background be placed in the headline template.

In this case, the answer provides a method to insert a vertical shaded background or a simple background.

Simple background

\documentclass[xcolor=dvipsnames,14pt]{beamer}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\usetikzlibrary{calc}
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\setlength\parskip{0.75em}
\setlength\parindent{0pt}
\setbeamersize{text margin left=3mm,text margin right=3mm}{}
\setbeamerfont{section in head/foot}{size=\scriptsize}
\setbeamerfont{subsection in head/foot}{size=\scriptsize}
\setbeamerfont{date in head/foot}{size=\scriptsize}
\setbeamercolor{section in head/foot}{fg=black,bg=gray}
\setbeamercolor{subsection in head/foot}{fg=black,bg=gray}
\setbeamercolor{date in head/foot}{fg=black,bg=gray}

% uniform color
\setbeamercolor{shadedhead}{bg=blue}

\setbeamertemplate{headline}{
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}%
\end{beamercolorbox}%
}\vskip0pt
\leavevmode\hbox{%
% uniform
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{shadedhead}%
\end{beamercolorbox}%

}\vskip0pt
}

\begin{document}
\section{Section title}
\subsection{Subsection title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}

\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}

\subsection{Subsection second title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}

\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}
\end{document}

The background has been inserted by means of:

\leavevmode\hbox{%
% uniform
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{shadedhead}%
\end{beamercolorbox}%
}

and the color definition could be modified by changing:

\setbeamercolor{shadedhead}{bg=blue}

You can adapt the dimensions in the options of the beamercolorbox environment.

Two frames of the result:

enter image description here

enter image description here

Background with vertical shading

Let's define as first the shading:

% Shade definition
\pgfdeclareverticalshading{mytopshade}{\paperwidth}{%
    color(0pt)=(gray!40);
    color(10pt)=(gray)}

You can find further informations on the possible shadings in the pgfmanual (also related How to create a ball shading and to customize 3D lighting manually?).

Now we apply this shading in the headline template:

\leavevmode\hbox{%
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{}%
\begin{pgfpicture}{0pt}{0pt}{\paperwidth}{3ex}
    \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{3ex}}
    \pgfusepath{clip}
    \pgftext[left,base]{\pgfuseshading{mytopshade}}
  \end{pgfpicture}
\end{beamercolorbox}%
}

The whole code:

\documentclass[xcolor=dvipsnames,14pt]{beamer}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\usetikzlibrary{calc}
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.5pt}
\setlength\parskip{0.75em}
\setlength\parindent{0pt}
\setbeamersize{text margin left=3mm,text margin right=3mm}{}
\setbeamerfont{section in head/foot}{size=\scriptsize}
\setbeamerfont{subsection in head/foot}{size=\scriptsize}
\setbeamerfont{date in head/foot}{size=\scriptsize}
\setbeamercolor{section in head/foot}{fg=black,bg=gray}
\setbeamercolor{subsection in head/foot}{fg=black,bg=gray}
\setbeamercolor{date in head/foot}{fg=black,bg=gray}

% Shade definition
\pgfdeclareverticalshading{mytopshade}{\paperwidth}{%
    color(0pt)=(gray!40);
    color(10pt)=(gray)}

\setbeamertemplate{headline}{
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=54mm,ht=3ex,dp=1ex,right]{section in head/foot}%
\usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=65mm,ht=3ex,dp=1ex,right]{subsection in head/foot}%
\usebeamerfont{subsection in head/foot}\insertsubsectionhead\hspace*{2ex}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=9mm,ht=3ex,dp=1ex,right]{date in head/foot}%
\usebeamerfont{date in head/foot}\insertframenumber{}\hspace*{2ex}%
\end{beamercolorbox}%
}\vskip0pt
\leavevmode\hbox{%
\begin{beamercolorbox}[wd=\textwidth,ht=3ex,dp=2ex]{}%
\begin{pgfpicture}{0pt}{0pt}{\paperwidth}{3ex}
    \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{3ex}}
    \pgfusepath{clip}
    \pgftext[left,base]{\pgfuseshading{mytopshade}}
  \end{pgfpicture}
\end{beamercolorbox}%
}\vskip0pt
}

\begin{document}
\section{Section title}
\subsection{Subsection title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}

\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}

\subsection{Subsection second title}
\begin{frame}
\frametitle{Frame title}
some text
\end{frame}

\begin{frame}
\frametitle{Frame title 2}
some text
\end{frame}
\end{document}

Now the same frames of the previous example are diplayed as:

enter image description here

enter image description here

You must log in to answer this question.

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