4

In my presentation composed with the beamer class I have the following piece of code:

\documentclass[dvips, 9pt, unicode, t]{beamer}
\usepackage{ifthen}
\usetheme{CambridgeUS}

\setbeamertemplate{footline}{%
\leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,left]{author in head/foot}%
    \usebeamerfont{author in head/foot}\hspace*{1em}good footline
  \end{beamercolorbox}}%
\vskip0pt}

\begin{document}

  \begin{frame}
    Frame one (with footline)
  \end{frame}

  \begin{frame}
    Frame two (with footline)
  \end{frame}

\end{document}

which gives the right footlines. However, the following piece of code

\documentclass[dvips, 9pt, unicode, t]{beamer}
\usepackage{ifthen}
\usetheme{CambridgeUS}

\newcommand\Switttch{0}
\setbeamertemplate{footline}{%
\ifthenelse{\equal{\Switttch}{0}}{}{\leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,left]{author in head/foot}%
    \usebeamerfont{author in head/foot}\hspace*{1em}bad footline
  \end{beamercolorbox}}%
  \vskip0pt}}

\begin{document}

  \begin{frame}
    Frame one (without footline)
  \end{frame}

  \renewcommand\Switttch{1}
  \begin{frame}
    Frame two (with footline)
  \end{frame}

\end{document} 

gives a footline on second frame which overlaps with the bottom line of the page. What's wrong with the second piece of code? (I want to switch on and switch off the footline for different frames.)

godsdog
  • 75
  • Kindly post a complete MWE starting from \documentclass and ending with \end{document} –  Oct 18 '12 at 22:51

3 Answers3

4

(Moved my answer from a comment to here, and now put in the context of the MWE given.)

beamer only calculates the size (height) of the headlines and footlines once (at \begin{document}, I think). If you wish to have footlines of different heights on different slides and you don't want to take egreg's approach of using struts to make all footline's appear the same height, you can to ask beamer to recalculate this by calling \beamer@calculateheadfoot before every frame in which the footline height changes from the previous frame.

I have modified your syntax for changing \Switttch to facilitate this.

\documentclass[dvips, 9pt, unicode, t]{beamer}
\usepackage{ifthen}
\usetheme{CambridgeUS}

\newcommand\Switttch{0}
\makeatletter
\newcommand*\setSwitttch[1]{\renewcommand\Switttch{#1}\beamer@calculateheadfoot}
\makeatother
\setbeamertemplate{footline}{%
\ifthenelse{\equal{\Switttch}{0}}{}{\leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,left]{author in head/foot}%
    \usebeamerfont{author in head/foot}\hspace*{1em}bad footline
  \end{beamercolorbox}}%
  \vskip0pt}}

\begin{document}

  \begin{frame}
    Frame one (without footline)
  \end{frame}

  \setSwitttch{1}
  \begin{frame}
    Frame two (with footline)
  \end{frame}

\end{document}

The footline now appears in the correct position on both slides, and the navigation buttons/main slide content now finishes just above the footline.

  • Works perfect. The only question. What does * in command \newcommand*\setSwitttch[1]{\renewcommand\Switttch{#1}\beamer@calculateheadfoot} mean?

    PS For those who don't know sense of commands \makeatletter and \makeatother see here

    – godsdog Oct 23 '12 at 10:56
  • 1
    @godsdog. The star means that the command is not to be declared \long, so it will not accept paragraph breaks in its argument (that is normally a mistake that it is helpful to catch; the error will be along the lines of paragraph ended before \setSwitttch was complete). See e.g. this question for more: http://tex.stackexchange.com/q/1050/17427 – cyberSingularity Oct 23 '12 at 14:05
2

I believe that the simpler definition

\setbeamertemplate{footline}{%
  \ifthenelse{\equal{\Switttch}{0}}
    {\vrule height 2.25ex depth 1ex width 0pt}
    {\begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,left]{author in head/foot}%
     \usebeamerfont{author in head/foot}\hspace*{1em}Good footline
     \end{beamercolorbox}}}

will do what you're looking for.

egreg
  • 1,121,712
0

With the current beamer development version (should be included in beamer v3.70 or newer), beamer now recalculates the head- and footheight at the start of each frame, so your example will work fine out of the box

\documentclass[9pt, unicode, t]{beamer}
\usepackage{ifthen}
\usetheme{CambridgeUS}

\newcommand\Switttch{0} \setbeamertemplate{footline}{% \ifthenelse{\equal{\Switttch}{0}}{}{\leavevmode% \hbox{% \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex,left]{author in head/foot}% \usebeamerfont{author in head/foot}\hspace*{1em}bad footline \end{beamercolorbox}}% \vskip0pt}}

\begin{document}

\begin{frame} Frame one (without footline) \end{frame}

\renewcommand\Switttch{1} \begin{frame} Frame two (with footline) \end{frame}

\end{document}