[Tex/LaTex] Redefining infolines in beamer

beamer

I'm realizing my first presentation in beamer.
I'm using the CambridgeUS theme, and I want to redefine the infolines so I can show

  • the title of the presentation on the headline
  • author, institute, date and counter on the footline

I wrote the following code

\makeatletter
\setbeamertemplate{headline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{section in head/foot}\insertshorttitle\hspace*{2ex}
\end{beamercolorbox}%
}
\makeatother

\makeatletter
\setbeamertemplate{footline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{title in head/foot}\insertshortauthor
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshortinstitute
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
    \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
    \insertframenumber{} / \inserttotalframenumber\hspace*{2ex} 
\end{beamercolorbox}}%
\vskip0pt%
}
\makeatother

but i got the following error

File ended while scanning use of \beamer@sbtexec

I think the error is in the definition of headline.
In fact, if I wrote the following code

\makeatletter
\setbeamertemplate{headline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{section in head/foot}\insertshorttitle\hspace*{2ex}
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshortinstitute
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
    \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
    \insertframenumber{} / \inserttotalframenumber\hspace*{2ex} 
\end{beamercolorbox}}%
\vskip0pt%
}
\makeatother

all work well, but I had to define two useless beamercolorbox.
Where is the error?

Also, I would like to hide the headlines in the first frame of the presentation.

How can I do?

Best Answer

You are missing a final closing brace in the headline definition:

\documentclass{beamer}
\usetheme{CambridgeUS}

\makeatletter
\setbeamertemplate{headline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.75ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{section in head/foot}\insertshorttitle\hspace*{2ex}
\end{beamercolorbox}}% <- this closing brace was missing
}

\setbeamertemplate{footline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{title in head/foot}\insertshortauthor
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshortinstitute
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
    \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
    \insertframenumber{} / \inserttotalframenumber\hspace*{2ex} 
\end{beamercolorbox}}%
\vskip0pt%
}
\makeatother

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

\begin{document}

\begin{frame}
test
\end{frame}

\end{document}

enter image description here

I took the liberty to slightly increase the height for the box in the headline (this is just a suggestion, of course, and you can revert to your original settings).

To suppress the headline and footline, use the plain option for frame; to suppress one template only, redefine it locally to be empty:

\documentclass{beamer}
\usetheme{CambridgeUS}

\makeatletter
\setbeamertemplate{headline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.75ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{section in head/foot}\insertshorttitle\hspace*{2ex}
\end{beamercolorbox}}%
}

\setbeamertemplate{footline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
    \usebeamerfont{title in head/foot}\insertshortauthor
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshortinstitute
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
    \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
    \insertframenumber{} / \inserttotalframenumber\hspace*{2ex} 
\end{beamercolorbox}}%
\vskip0pt%
}
\makeatother

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

\begin{document}

\begin{frame}[plain]
test
\end{frame}

\begingroup
\setbeamertemplate{headline}{}
\begin{frame}
test
\end{frame}
\endgroup

\begingroup
\setbeamertemplate{footline}{}
\begin{frame}
test
\end{frame}
\endgroup

\begin{frame}
test
\end{frame}

\end{document}

enter image description here