[Tex/LaTex] Beamer – titlepage overlay

beamer

I would like to have an overlay on the titlepage of my beamer presentation. More specifically I would like to have two versions of my title (one English, one German) that can be switched. Most preferably such that the surrounding box and the rest of this frame do not change (get shifted).

Schematically the document looks like this:

\documentclass{beamer}
\mode<presentation>
{
  \usetheme{Madrid}
}
%more setup stuff

\title[]{Title A}
%\title[]{Title B}

\begin{document}
  \begin{frame}
    \titlepage
    %some logos etc. 
  \end{frame}
\end{document}

Now my goal would be to have one slide with "Title A" and one with "Title B", just as if I would use overlay specifications on a normal slide. Is there a way to do this within beamer?


Edit:

Here's an explicit example of two titles that are of different length and for which there should be no change in the surrounding title box. See discussion below.

\title[]{%
\only<1>{This is a rather short title}%
\only<2>{Und dies ist eine deutlich längere Version, die sich über mehrere Zeilen erstreckt}%
}

Without any special treatment the titles are of different height and the rest of the frame shifts when switching.

Best Answer

You could use \only inside \title:

\documentclass{beamer}
\mode<presentation>
{
  \usetheme{Madrid}
}

\title[]{\only<1>{Title A}\only<2>{Title B}}

\begin{document}
  \begin{frame}
    \titlepage
    %some logos etc. 
  \end{frame}
\end{document}

EDIT: here's a modified version when the titles have different length and have different heights; all the code between \makeatletter and \makeatother was written by Martin Scharrer in his answer to Beamer alt command like visible instead of like only (all the credit goes to him and to Matthew Leingang for pointing this out to me). The only modification I added was a new command to use \parboxes and to allow different vertical alignment for the titles.

\documentclass{beamer}
\mode<presentation>
{
  \usetheme{Madrid}
}

% all the code between \makeatletter and \makeatother is from Martin Scharrer
% in https://tex.stackexchange.com/questions/13793/beamer-alt-command-like-visible-instead-of-like-only/13830#13830
\makeatletter
% Detect mode. mathpalette is used to detect the used math style
\renewcommand<>\Alt[2]{%
    \begingroup
    \ifmmode
        \expandafter\mathpalette
        \expandafter\math@Alt
    \else
        \expandafter\make@Alt
    \fi
    {{#1}{#2}{#3}}%
    \endgroup
}

% Un-brace the second argument (required because \mathpalette reads the three arguments as one
\newcommand\math@Alt[2]{\math@@Alt{#1}#2}

% Set the two arguments in boxes. The math style is given by #1. \m@th sets \mathsurround to 0.
\newcommand\math@@Alt[3]{%
    \setbox\z@ \hbox{$\m@th #1{#2}$}%
    \setbox\@ne\hbox{$\m@th #1{#3}$}%
    \@Alt
}

% Un-brace the argument
\newcommand\make@Alt[1]{\make@@Alt#1}

% Set the two arguments into normal boxes
\newcommand\make@@Alt[2]{%
    \sbox\z@ {#1}%
    \sbox\@ne{#2}%
    \@Alt
}

% Place one of the two boxes using \rlap and place a \phantom box with the maximum of the two boxes
\newcommand\@Alt[1]{%
    \alt#1%
        {\rlap{\usebox0}}%
        {\rlap{\usebox1}}%
    \setbox\tw@\null
    \ht\tw@\ifnum\ht\z@>\ht\@ne\ht\z@\else\ht\@ne\fi
    \dp\tw@\ifnum\dp\z@>\dp\@ne\dp\z@\else\dp\@ne\fi
    \wd\tw@\ifnum\wd\z@>\wd\@ne\wd\z@\else\wd\@ne\fi
    \box\tw@
}

% syntax: \AltTitl[<position>]{<TitleA>}{<TitleA>}. Posible values for <position are> c,t,b
% default: c
\newcommand\AltTitle[3][c]{%
  \Alt<2>{\parbox[#1]{.8\textwidth}{\Large\centering#2}}{\parbox[#1]{.8\textwidth}{\Large\centering#3}}
}
\makeatother

\title{\AltTitle[t]{Short Title A}{This is a really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really really long Title B}}
\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\end{document}