[Tex/LaTex] Scaling listings in beamer

scaling

This answer
scaling latex objects
advises to use \resizebox to scale Latex objects.

However, this approach fails when rescaling a listing in beamer:

\documentclass{beamer}
\usepackage{listings}
\begin{document}
\begin{frame}[fragile]
  \resizebox{\textwidth}{!}{%                                                                                                                                                                               
    \begin{lstlisting}
      some -program --code "Not fitting into page"
    \end{lstlisting}
  }
\end{frame}
\end{document}

The error one gets is

! Argument of \lst@next has an extra }.

How to scale a listing in beamer?

Best Answer

As said in the comment you cannot pass verbatim stuff as arguments to a macro. But for listings you can easily change the font size.

\begin{frame}[fragile]
  \begin{lstlisting}
some -program --code "Not fitting into page"
  \end{lstlisting}
  \begin{lstlisting}[basicstyle=\small]
some -program --code "Not fitting into page"
  \end{lstlisting}
  \begin{lstlisting}[basicstyle=\footnotesize]
some -program --code "Not fitting into page"
  \end{lstlisting}
  \begin{lstlisting}[basicstyle=\fontsize{8}{9}\selectfont]
some -program --code "Not fitting into page"
  \end{lstlisting}
\end{frame}

enter image description here

If you want to change it for the document or a complete frame you can use lstset.

\begin{frame}[fragile]
  \lstset{basicstyle=\small}
  \begin{lstlisting}
some -program --code "Not fitting into page"
  \end{lstlisting}
  \begin{lstlisting}[basicstyle=\normalsize]
some -program --code "Not fitting into page"
  \end{lstlisting}
\end{frame}

enter image description here