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 have the following problem with overlays in LaTeX beamer. On the first slide I want to display

enter image description here

while the second slide should show

enter image description here

The difficulty is to achieve that the amount of space occupied by 3+4+5 is also reserved on the first slide even though 12 would actually need less space.

The MWE below does NOT solve this problem. Is there any solution?

\documentclass{beamer}
\begin{document}
\frame{
\uncover<1-2>{}
1+2+\alt<1>{12}{3+4+5}+6+7=28
}
\end{document} 
share|improve this question
    
An easy fix would be \alt<1>{\phantom{3+}1\phantom{+5}}{3+4+5}, but it works if and only if the first alternative wouldn't have two digits. –  Claudio Fiandrino Mar 30 '13 at 10:43
add comment

2 Answers

up vote 6 down vote accepted
\documentclass{beamer}

\newcommand\centerin[2]{{%
\ifmmode\def\dollar{$}\else\def\dollar{}\fi
\settowidth{\dimen8}{\dollar#2\dollar}%
\makebox[\dimen8]{\dollar#1\dollar}}}

\def\altcenterin<#1>#2#3{\alt<#1>{\centerin{#2}{#3}}{#3}}

\begin{document}
\frame{


\uncover<1-2>{}
1+2+\altcenterin<1>{12}{3+4+5}+6+7=28
}
\end{document} 
share|improve this answer
add comment

You can use features of beamer and of mathtools, combined with calc:

\documentclass{beamer}
\usepackage{mathtools,calc}

\newcommand<>\mathalt[2]{%
  \alt#3{\mathmakebox[\widthof{$#2$}]{#1}}{#2}%
}

\begin{document}

\begin{frame}

\uncover<1-2>{}
$1+2+\mathalt<1>{12}{3+4+5}+6+7=28$

\end{frame}
\end{document}

First subframe:

enter image description here

Second subframe:

enter image description here

(The small difference is due just to the screen capture, sorry.)

share|improve this answer
add comment

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.