Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
With characteristic German efficiency Martin Scharrer has already answered this question: tex.stackexchange.com/questions/13793/… –  Matthew Leingang May 12 '11 at 21:38
add comment

1 Answer

up vote 2 down vote accepted

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 http://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}
share|improve this answer
    
Cool, I hadn't thought it to be possible to put overlay specifications into the title like this. However, one problem remains: the titles occupy a different number of lines and in the above solution this leads to a change in the size of the surrounding box. Could this be rectified somehow? Something like an overprint environment... (this does unfortunately not work out-of-the-box in the title). –  janitor048 May 11 '11 at 8:22
    
@janitor048: You can always appropriately "complete" the shortest tile: \title[]{\only<1>{Title A\\\mbox{\strut}\\\mbox{\strut}}\only<2>{\strut Really really really really really really really really really really really really really really really really really really long Title B}} –  Gonzalo Medina May 11 '11 at 11:40
    
I think this is getting close but the boxes are not exactly of equal size and the text still shifts. Maybe some savebox hack would do, I'll give it a try.. –  janitor048 May 11 '11 at 12:57
    
@janitor048: with the example I just gave you there's no text shifting and the title box has the same size in both slides. If you are getting a different result, perhaps you could add an Edit to your question with the actual titles, so I could suggest you a solution. –  Gonzalo Medina May 11 '11 at 13:01
    
@Gonzalo: I've edited my question to explicitly include an example for which the rest of the frame shifts (not my actual titles, but those might still change anyhow, so I would need a generic solution..). It also shifts, albeit only slightly, when using your \mbox approach. –  janitor048 May 12 '11 at 20:05
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.