How can I uncover a certain lstlisting environment on a particular slide using \onslide or \uncover?

For example:


  \onslide<1-> HI
  \onslide<2-> \begin{lstlisting} int i = 0; \end{lstlisting}

Verbatim material cannot appear in an argument to another command (up to a certain point you could try using an external file and inputting it with \lstinputlisting) and use \uncover on \onslide, but the best approach here is to use the onlyenv environment for your listing (since the frame contains verbatim material it requires the fragile option):


  int i = 0; 

I also added an optional overlayarea environment to prevent possible "jumps". An animation of the result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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