5

I have this LaTeX code:

    \lstset{
    language=Java,
    tabsize=8,
    keepspaces,
    extendedchars=true,
    rulecolor=\color{black},
    basicstyle=\footnotesize,
    aboveskip=5pt,
    upquote=true,
    columns=fixed,
    showstringspaces=false,
    extendedchars=true,
    breaklines=true,
    frame=single,
    showtabs=true,
    showspaces=false,
    showstringspaces=false,
}

\begin{frame}[fragile]
\begin{lstlisting}
    public class Teddy {
        public MethodName(String name, int var) {
             this.name = name;
        }
    }
\end{lstlisting}
\end{frame}

Beamer ignores my tabs inside the lstlisting because my frame is fragile. But I need it to be fragile, because I get the "Runaway Argument"-Exception, when there is no fragile.

What can I do, except importing the Lsting from an external file?

I don't want to define a new command for each source code listing, like proposed in this solution: How to prevent beamer from removing the tab alignment of lstlisting?

  • 2
    Simply replace your tabs with spaces. This should be easily possible with a decent editor. – Martin Scharrer Nov 5 '11 at 11:21
5

use it this way:

\documentclass{beamer}
\usepackage{listings}
    \lstset{
    language=Java,
    tabsize=8,
    keepspaces,
    extendedchars=true,
    rulecolor=\color{black},
    basicstyle=\footnotesize,
    aboveskip=5pt,
    upquote=true,
    columns=fixed,
    showstringspaces=false,
    extendedchars=true,
    breaklines=true,
    frame=single,
    showtabs=true,
    showspaces=false,
    showstringspaces=false,
}
\begin{document}
\defverbatim\lst{%
\begin{lstlisting}
    public class Teddy {
        public MethodName(String name, int var) {
            this.name = name;
        }
    }
\end{lstlisting}
}
\begin{frame}
\lst
\end{frame}
\end{document}

enter image description here

  • yea, gut then I have to define a command for every listing – Tobi Nov 5 '11 at 16:29

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.