[Tex/LaTex] Adding background color to active sections of beamer sidebar

backgroundsbeamercolorthemes

I have designed a theme for my beamer presentation which has sidebar in it.
Now I want to add background color for active items in the sidebar. How can I do that?

Following picture shows what I intend to do.

enter image description here

Best Answer

Since you are not providing a MWE I'm using a standard sidebar theme to show what you need to do in principle. If you need something more specific for your use case please provide a MWE with your code.

\documentclass{beamer}
\usepackage{tikz}
\usetheme{Hannover}

\setbeamertemplate{section in sidebar}{\tikz{\node[fill=black!80,text=white]{\insertsectionhead};}}

\begin{document}
\section{first}
\begin{frame}
this is a test  
\end{frame}
\section{second}
\begin{frame}
this is a test 2  
\end{frame}
\end{document}

enter image description here

You can customize the appearance as much as you like by styling the TikZ node.


If you also want sections to be highlighted when there are subsections (by default Beamer shades a section when it has subsections), you need to add the following code to your preamble (kindly provided by @diabonas)

\usepackage{etoolbox}
\makeatletter
\patchcmd{\insertverticalnavigation}%
{\ifx\beamer@nav@css\beamer@hidetext{\usebeamertemplate{section in sidebar}}\else{\usebeamertemplate{section in sidebar shaded}}\fi}%
{{\usebeamertemplate{section in sidebar}}}{}{}
\makeatother