2

I cannot find a way to apply \only<n>{content} to a whole itemize environment.

My first approach was:

\only<1>{\begin{itemize}
    \item A
\end{itemize}}

But I get multiple error messages at compile time. I have also tried multiple variations found on the web. But I cannot find a way of hide (not occupying space) the whole list.


EDIT:

Here a minimum non-working example, after reading the comment of @Schrödinger's cat I realized that the problem arises when I use the lstMakeShortInline, in this case, |First|. Without it, it works.

\documentclass{beamer}
\usepackage{listings}
\lstMakeShortInline[language=C,basicstyle=\ttfamily]|
\begin{document}
\begin{frame}[fragile]{Title}
  \begin{columns}[T]
    \column{0.55\textwidth}
    \column{0.45\textwidth}
    \only<1>{
      \begin{itemize}
      \item My code: |First|
      \end{itemize}
    }
    \only<2>{
      \begin{itemize}
      \item Second
      \end{itemize}
    }
  \end{columns}
\end{frame}
\end{document}

2
  • 1
    Please post a complete example that produces the error. I can't reproduce the problem. \documentclass{beamer} \begin{document} \begin{frame}[t] \frametitle{Test} \only<1>{\begin{itemize} \item A \end{itemize}} \pause \only<2>{\begin{itemize} \item B \end{itemize}} \end{frame} \end{document} works fine.
    – user194703
    Feb 27, 2020 at 6:07
  • Please change your title to reflect the real problem between \only and the listing package. Feb 27, 2020 at 10:46

1 Answer 1

0

Use the onlyenv environment instead of the \only macro:

\documentclass{beamer}
\usepackage{listings}
\lstMakeShortInline[language=C,basicstyle=\ttfamily]|
\begin{document}
\begin{frame}[fragile]{Title}
  \begin{columns}[T]
    \column{0.55\textwidth}
    \column{0.45\textwidth}
    \begin{onlyenv}<1>
      \begin{itemize}
      \item My code: |First|
      \end{itemize}      
    \end{onlyenv}
    \begin{onlyenv}<2>
      \begin{itemize}
      \item Second
      \end{itemize}
    \end{onlyenv}
  \end{columns}
\end{frame}
\end{document}
6
  • Can't we just add <2> to itemize directly?
    – daleif
    Feb 27, 2020 at 10:59
  • @daleif This is not the purpose of the original question: "How to apply overlay \only to a whole itemize environment?" Feb 27, 2020 at 12:08
  • My reason for asking is if the OP is not aware of this option. Many users never comes past the first few constructions they learn
    – daleif
    Feb 27, 2020 at 12:11
  • @daleif Add <x> to itemize acts like \visible not like \only... Feb 27, 2020 at 12:14
  • I was (even after reading a whole lot) not aware of the \onlyenv environment, I will try it and come back.
    – onlycparra
    Feb 28, 2020 at 3:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .