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.

Is there a way to make the command \only work on a block in beamer?

Or is there another way to make a block appear and then disappear?

Here is a part of my code:

\documentclass{beamer}
\usetheme{CambridgeUS}


\usepackage[french]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{moreverb}
\usepackage{listings}
\begin{document}

\begin{frame}[fragile]{Creation des outils principaux}
  % - Le titre doit résumer le transparent dans un langage compréhensible
  %   par tous ceux qui ne suivront rien de ce qu'il y a sur ce transparent.
  \begin{itemize}
        \item Recuperation des donnees entrées dans le terminal
            \only<2>{
                \begin{exampleblock}{Opt Parse}
\begin{lstlisting}[firstnumber=0]
import optparse
def parser():
    parser = optparse.OptionParser(        description = "Dessinateur de fonctions")
    parser.add_option('-o', type=str, action = "store",
                        default="out.ppm", dest="filename",
                        help='filename. Default : out.ppm')
    return parser.parse_args()
if __name__ == '__main__':
    (opts, args) = parser()
\end{lstlisting}
                \end{exampleblock}
            }
    \end{itemize}
\end{frame}

\end{document}
share|improve this question
    
I had the same problem when using a tikZ \matrix command. All blocks afterwards need not start with \only but with \begin{block}{title}<5-> –  Sebastian Apr 14 '13 at 20:39
add comment

1 Answer 1

up vote 8 down vote accepted

I don't see your problem. I built this MWE:

\documentclass{beamer}
\usetheme{CambridgeUS}

\begin{document}

\begin{frame}{Title of this frame}
% first block appears at first
\only<1>{
    \begin{block}{First block}
    Hello
    \end{block}
}
% first block disappears and the second appears
\only<2>{
    \begin{block}{Second block}
    Hello again
    \end{block}
}

\end{frame}

\end{document}

getting these two frames:

enter image description here

enter image description here

As you can see, the frame number is always the same and the second block appears after the first one, that is not more visible.

Edit

After you posted your MWE I got your problem. Maybe my solution will not completely satisfy you, but it works.

First: the option fragile is needed anyway. Secondly, since I noticed that the code occupies more or less the whole frame (even setting the font size smaller), I decided in my solution to put it outside the itemize environment.

This is the new MWE:

\documentclass{beamer}
\usetheme{CambridgeUS}

\usepackage[french]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{moreverb}
\usepackage{listings}
\lstset{basicstyle={\footnotesize}}
\begin{document}

\begin{frame}[fragile]{Creation des outils principaux}
  % - Le titre doit résumer le transparent dans un langage compréhensible
  %   par tous ceux qui ne suivront rien de ce qu'il y a sur ce transparent.
\begin{itemize}
\item<1-> Recuperation des donnees entrées dans le terminal
\end{itemize}
\begin{exampleblock}{Opt Parse}<2>
\begin{lstlisting}[firstnumber=0]
import optparse
def parser():
    parser = optparse.OptionParser(\
    description = "Dessinateur de fonctions")
    parser.add_option('-o', type=str, action = "store",
                        default="out.ppm", dest="filename",
                        help='filename. Default : out.ppm')
    return parser.parse_args()
if __name__ == '__main__':
    (opts, args) = parser()
\end{lstlisting}
\end{exampleblock}

\end{frame}
\end{document}

The result is shown in the following two frames:

enter image description here

enter image description here

Notice that the key point is having inserted <1-> to the item and <2> for the exampleblock. In this way the sentence of the item is still visible when the exampleblock appears.

share|improve this answer
    
When I do yours it's working but mine keep being stuck Maybe it's because the block are in a itemize? –  lpostula Apr 20 '12 at 9:10
    
@kasmanit: Please add a minimal working example (MWE) that illustrates your problem! –  Daniel Apr 20 '12 at 9:16
    
In fact it seems that it's the listing with the code that cause trhe problem, when I remove it it's working –  lpostula Apr 20 '12 at 9:19
    
Perhaps you forgot to use the frame option fragile when you inserted the code by means of listings. –  Claudio Fiandrino Apr 20 '12 at 9:20
    
When I add the fragile It gave me utf8x error (i gonna fix this later, it's not the main problem), beacause it says that there is missing } but I am sure tht everything is fine –  lpostula Apr 20 '12 at 9:32
show 3 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.