[Tex/LaTex] overfull vbox with beamercolorbox

beamerspacingwarnings

In a latex-beamer document, I am using a custom headline template. It produces a headline only when in a section. Here is a stripped down version:

\documentclass{beamer}
\usepackage{times} % gets rid of fontsize warnings
\setbeamercolor{section in head}{bg=yellow!80!black,fg=structure} 
%% \setbeamercolor{lower separation line head}{bg=yellow!50!black}
\setbeamertemplate{headline}{
   \ifx\insertsection\empty\else
   \usebeamerfont{section in head}
   \begin{beamercolorbox}[ht=2ex,dp=1ex,leftskip=2ex]{section in head}
     \insertsection 
   \end{beamercolorbox}
   %%\begin{beamercolorbox}[colsep=0.5pt]{lower separation line head}\end{beamercolorbox}
   \fi
   \vspace*{5pt}
}

\begin{document}
\begin{frame}
  % frame has empty headline
\end{frame}
 \section{A Section}
\begin{frame}
  % frame headline shows section title
\end{frame}
\end{document}

However, this code produces an "overfull vbox": Overfull \vbox (9.41396pt too high) has occurred while \output is active []

I could ignore it because the result looks fine, but I'd like to know why this is happening and how I could deal with it, mostly because it is irritatint to see this printed out over 200 times.

(Note: this does not happen when commenting out lines 6 and 12, the ones with \if and \fi.)

Best Answer

Modify the line 5 to say:

 \ifx\insertsection\empty\hrule height2ex depth1ex width0pt\else

I believe that what happens is beamer calculates the total height of the head at the beginning of the document, before \insertsection is set, and uses this value to calculate the other dimensions of the page. With the head empty, it expects the size of the head to be 0, and if the head is not empty, the whole page is overfull. Notice that on the pages with the section head, with the original code, the navigation line is pushed out of the page, so it disappears.