2

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?

2
  • 1
    The scaling would fail in any other documentclass as well, since you're using a verbatim environment like lstlisting inside of a macro -- that is not possible.
    – user31729
    Feb 13, 2018 at 5:22
  • 1
    Please do not scale elements which contain text, this will give suboptimal results! Feb 13, 2018 at 10:11

1 Answer 1

6

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

You must log in to answer this question.

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