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?

1
  • 2
    Simply replace your tabs with spaces. This should be easily possible with a decent editor. Nov 5, 2011 at 11:21

1 Answer 1

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

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

You must log in to answer this question.

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