Section numbering in Beamer ('CambridgeUS' theme)

Does anybody know how to make latex put the number for a section presented in header?

\documentclass{beamer}
%\usetheme{Warsaw}
\usetheme{CambridgeUS}
\begin{document}

\section{Section a}
\begin{frame}
Test frame
\end{frame}
\end{document}


-

For those themes using the infolines outer theme, such as CambridgeUS, you can add the following lines to the preamble:

\setbeamertemplate{headline}
{
\leavevmode%
\hbox{%
\end{beamercolorbox}%
\end{beamercolorbox}}%
\vskip0pt%
}


EDIT: In the following example I defined a \Switch command that allows to turn on/off the numbering of the sections in the headline; initially, it is set to 0 (turn off numbering), but redefining it to be 1 will turn on the numbering; the command can be redefined as many times as required:

\documentclass{beamer}
\usepackage{ifthen}
\usetheme{CambridgeUS}

\newcommand\Switch{0}
\ifthenelse{\equal{\Switch}{1}}
{\thesection.}{}}

{
\leavevmode%
\hbox{%
\end{beamercolorbox}%
\end{beamercolorbox}}%
\vskip0pt%
}
\begin{document}

\begin{frame}
Test frame with un-numbered section
\end{frame}

\renewcommand\Switch{1}
\section{Section a}
\begin{frame}
Test frame with numbered section
\end{frame}

\renewcommand\Switch{0}
\begin{frame}
Test frame with un-numbered section
\end{frame}

\end{document}

-
Thank you very much! It works. Minor change "\thesection." instead of "\thesection" makes exactly that what I want. –  godsdog May 29 '11 at 16:03
I am sorry very much. There is a bug. Section "0." appeared in title frame. Are there any ideas how to manage with it? –  godsdog May 29 '11 at 16:30
To place @Gonzalo Medina's piece of code AFTER the title frame is enough to solve the problem with "0." in header on title frame. –  godsdog May 29 '11 at 16:57
@Andriy Andrusyk: I presume that the undesired number appears for frames not belonging to any section? If this is so, a quick fix would be to redefine \thesection locally for those frames: {\renewcommand\thesection{} \begin{frame} Test frame \end{frame} }. Notice the grouping { and } braces to keep the redefinition local. –  Gonzalo Medina May 29 '11 at 16:57
@Andriy Andrusyk: the problem with that redefinition is that now the dot will also appear if you label/cross-reference sections, and that might not be desirable. –  Gonzalo Medina May 30 '11 at 11:59

The solution of @Gonzalo Medina have to be a bit modified. If we want to manage with subsection number too we can modify the code in the following way:

\documentclass{beamer}
\usepackage{ifthen}
\usetheme{CambridgeUS}

\newcommand\Switch{0}
\ifthenelse{\equal{\Switch}{1}}
{\thesection.}{}}
\ifthenelse{\equal{\Switch}{1}}
{\thesubsection. }{}}
\ifthenelse{\equal{\thesubsection}{0}}

{
\leavevmode%
\hbox{%
\end{beamercolorbox}%
\end{beamercolorbox}}%
\vskip0pt%
}

\begin{document}

\begin{frame}
Test frame with un-numbered section
\end{frame}

\renewcommand\Switch{1}
\section{Section a}
\begin{frame}
Test frame with numbered section
\end{frame}

\renewcommand\Switch{0}
\begin{frame}
Test frame with un-numbered section
\end{frame}

\renewcommand\Switch{1}
\section{Section a2}
\begin{frame}
Test frame with numbered section again
\end{frame}

\subsection{Subsection a2.1}
\begin{frame}
Test frame with numbered subsection again
\end{frame}

\end{document}

-