[Tex/LaTex] How to add/insert a rule in the headline and footline

beamerformatting

When we use the specified format from beamer, \documentclass[compress]{beamer}, how do we add/insert a black line above the headline and under the footline into each slide?

\documentclass[compress]{beamer}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[frame number]{}

\setbeamercolor{section in head/foot}{fg=secinhead,bg=black}
\setbeamercolor{subsection in head/foot}{fg=secinhead,bg=black}

\setbeamerfont{footline}{size=\tiny}

\usecolortheme[rgb={0,0,0}]{structure}

\useinnertheme{circles}
\newenvironment{proenv}{\only{\setbeamercolor{local structure}{fg=black}}}{}


\useoutertheme{infolines}

\usefonttheme{structurebold}

\setbeamertemplate{background canvas}[vertical shading][bottom=white,top=white]

Best Answer

This can be achieved using

\addtobeamertemplate{headline}{}{\rule{\paperwidth}{3pt}}
\addtobeamertemplate{footline}{\rule{\paperwidth}{3pt}}{}

A little example using the relevant settings from the original code:

\documentclass[compress]{beamer}
\usetheme{Montpellier}
\useoutertheme{infolines}

\author{The Author}
\title{The Title}
\institute{The Institute}

\addtobeamertemplate{headline}{}{\rule{\paperwidth}{3pt}}
\addtobeamertemplate{footline}{\rule{\paperwidth}{3pt}}{}

\begin{document}

\begin{frame}
test
\end{frame}

\end{document}

The result:

enter image description here

The rules I chose in the example are perhaps too thick; instead of 3pt, select the desired value for the thickness.