[Tex/LaTex] How to configure the verbatim text

verbatim

In LaTex, I use \verbatim to add a block of text. But the problem is that the verbatim text doesn't follow the page style, and it exceeds the page boundary if the text is long. The result is shown as below:

enter image description here

As you can see, the example call exceeds the boundary. That's where I use verbatim. The following is my code to set up verbatim text, could anyone tell me how to fix this problem? I will appreciate. I am kind of in a rush to get it done.

% Used by @verbatim ... @endverbatim
\newenvironment{DoxyVerb}{%
  \fontencoding{OT1}\fontfamily{cmr}\fontseries{b}\fontshape{n}\fontsize{10pt}{10}\selectfont%
  \verbatim%
}{%
  \endverbatim%
  \normalsize%
}

Best Answer

enter image description here

\documentclass[dvipsnames,cmyk]{article}
\usepackage{listings,xcolor}

\lstset
{
    breaklines=true,
    tabsize=3,
    showstringspaces=false
}


\lstdefinestyle{Common}
{
    extendedchars=\true,
    language={[Visual]Basic},
    frame=single,
    %===========================================================
    framesep=3pt,%expand outward.
    framerule=0.4pt,%expand outward.
    xleftmargin=3.4pt,%make the frame fits in the text area. 
    xrightmargin=3.4pt,%make the frame fits in the text area.
    %=========================================================== 
    rulecolor=\color{Red}
}

\lstdefinestyle{A}
{
    style=Common,
    backgroundcolor=\color{Yellow!10},
    basicstyle=\scriptsize\color{Black}\ttfamily,
    keywordstyle=\color{Orange},
    identifierstyle=\color{Cyan},
    stringstyle=\color{Red},
    commentstyle=\color{Green}
}

\lstdefinestyle{B}
{
    style=Common,
    backgroundcolor=\color{Black},
    basicstyle=\scriptsize\color{White}\ttfamily,
    keywordstyle=\color{Orange},
    identifierstyle=\color{Cyan},
    stringstyle=\color{Red},
    commentstyle=\color{Green}
}

\begin{document}

\begin{description}
\item[Visual Basic] is a programming language from Microsoft.
\begin{lstlisting}[style=A]%please try style=B
Option Explicit

Sub Signal(strSignalfolge As String, Optional lngTakt As Long = 100)
'Prozedur erzeugt eine Serie von Warntönen.
'Die optionale Variable lngTakt gibt den Takt in Millisekunden vor (Standard: 100 ms)
'Das Muster kann über die String-Variable strSignalfolge beeinflusst werden:
' Stern (*)     -> 1 Warnton
' Ziffern 1..9  -> 1..9 Takte Pause
' Leerzeichen   -> 1 Sekunde Pause
' Minus (-)     -> 1.5 Sekunden Pause
End Function
\end{lstlisting}
\item[Visual CSharp] is my favourite programming language.
\end{description}
\end{document}