Search code examples
latexlistings

Grayed listing environment with LaTeX


Form this LaTeX-workshop, I found I could make this listing style.

http://img441.imageshack.us/img441/2739/screenshot20100717at112.png

by defining a new environment.

\definecolor{mittelgrau}{gray}{0.85}%
\lstdefinestyle{StyleCommand}{%
style=StyleListingBasic, backgroundcolor=\color{mittelgrau}, prebreak=\mbox{\textbackslash{}}%
} 
\lstnewenvironment{bevel}[1][1] {\lstset{style=StyleCommand,linewidth=#1\linewidth}} {}%

Running the code, I get this error message.

ERROR: Package Listings Error: Couldn't load requested style.

What might be wrong?


Solution

  • I missed the \lstdefinestyle, and after some modification, I could make it work.

    \documentclass{article}
    
    \usepackage{color}              % Farben
    \usepackage{listings}           % für Listings
    
    % Listingdefinitionen
    \lstdefinestyle{StyleListingBasic}{%
         basicstyle=\ttfamily,       % Schriftstil
         frame=single,               % einfacher Rahmen
         framesep=1pt,               % Abstand des Rahmens
         framerule=0.8pt,            % Linienstaerke des Rahmens
         rulecolor=\color{mittelgrau},  % Farbe der Rahmenlinie
         breaklines=true,            % automatischen Umbruch aktivieren
         breakindent=0pt             % Einrueckung nach Umbruch
    }
    
    \definecolor{mittelgrau}{gray}{0.85}%
    \lstdefinestyle{StyleCommand}{%
    style=StyleListingBasic, backgroundcolor=\color{mittelgrau}, prebreak=\mbox{\textbackslash{}}%
    } 
    \lstnewenvironment{Befehl}[1][1] {\lstset{style=StyleCommand,linewidth=#1\linewidth}} {}%
    
    \begin{document}
    \begin{Befehl} 
    ./robots-gui-helper 
    \end{Befehl}%
    
    \end{document}