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'd like to have a conditional \multicolumn command depending on the slide, so I put it inside an alt or an only command, as follows:

\documentclass{beamer}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{frame}
\begin{equation*}
  \begin{array}{rlll}
  a&b&c&d\\
  A&\multicolumn{3}{l}{BCD}\\ %this is OK
   A&B&C&D\\ %as is this obviously...
  A&\only<-+>{\multicolumn{3}{l}{BCD}}\only<.->{B&C&D}\\ %but this
  A&\alt<-+>{\multicolumn{3}{l}{BCD}}{B&C&D}\\% and this do not compile
  A&\multicolumn{3}{l}{\only<-+>{BCD}\only<+->{\begin{tabular}{lll}B&C&D\\\end{tabular}}} %this line works, but, of course, gives the wrong alignment...
\end{array}
\end{equation*}
\end{frame}
\end{document}

The problem seems to be that LaTeX wants the \multicolumn command to appear as the first thing after an & or a newline...but then, as the last line shows, I don't know how to align with the other columns...

Currently I'm solving the problem using \hspace* but this is a bit of a ugly hack.

Any ideas on how I could get this to work properly??

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I tried sprinkling some magical fairy \expandafter dust around to see if the \only part could be processed before the ampersand, but it resulted in errors.

This requires only one token of repetition:

A\alt<-+>{&\multicolumn{3}{l}{BCD}}{&B&C&D}\\

I could not get your \only<-+>...\only<.-> construction to work with the +s. It does work with explicit numbers. But I assume that if the \alt construction works you'll take it as preferable.

Complete example:

\documentclass{beamer}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{frame}
\begin{equation*}
  \begin{array}{rlll}
   a&b&c&d\\
   A&\multicolumn{3}{l}{BCD}\\ %this is OK
   A&B&C&D\\ %as is this obviously...
   A\only<1>{&\multicolumn{3}{l}{BCD}}\only<2->{&B&C&D} \\% this works now, but not with -+ etc.
   A\alt<-+>{&\multicolumn{3}{l}{BCD}}{&B&C&D}\\% this works even with -+
\end{array}
\end{equation*}
\end{frame}
\end{document}
share|improve this answer
    
Of course!! putting the & inside the \alt works perfectly...I'm trying to implement it now in all the use cases and I'll see if still need help. Thanks Matthew! –  Yossi Farjoun Dec 1 '10 at 14:35
add comment

Hi I´m not quite sure what kind of layout you want to create, but i suppose you want some kind of appear/expand thing.

So for me this works:

    \begin{frame}

      \begin{tabular}{rlll} % works also in the array/equation construct
      a&b&c&d\\
      A&\multicolumn{3}{l}{BCD}\\ %this is OK
       A&B&C&D\\ %as is this obviously...
       \only<2>{A & \multicolumn{3}{l}{BCD}\\} \only<3>{A&B&C&D\\}  % slide 2 appearing slide 3 expanding
      \only<4>{A & \multicolumn{3}{l}{ BCD}\\} \only<5>{A&B&C&D\\} %  and this do not compile
      %A& \multicolumn{3}{l}{\only<-+>{BCD} \only<+->{\noindent\begin{tabular}{lll}B&C&D\\\end{tabular}}} %
% not sure what to do with that line so im dropping it
      \end{tabular}

    \end{frame}

So I´m not sure if that fits your expectation but it works. (Its not very efficient code because you have to type the A column every time.)

share|improve this answer
    
You could easily refactor out the duplicate code with some \newcommand calls - and when you're done, you could create a new command that does the work for you (to which you supply the first, second and third columns etc...) –  Tomas Lycken Dec 1 '10 at 11:30
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.