帮助以特定格式呈现代码

帮助以特定格式呈现代码

我怎样才能将代码放入图中所示的格式?

\usepackage{xcolor}
\usepackage{caption}

\lstset{
    language=csh,
    basicstyle=\footnotesize\ttfamily,
    numbers=left,
    numberstyle=\tiny,
    numbersep=5pt,
    tabsize=2,
    extendedchars=true,
    breakatwhitespace=true,
    breaklines=true,
    frame=single,
    framesep=3pt,
    stringstyle=\color{blue}\ttfamily,
    showspaces=false,
    showtabs=false,
    xleftmargin=40pt,
    framexleftmargin=40pt,
    framexrightmargin=40pt,
    framexbottommargin=4pt,
    commentstyle=\color{green},
    morecomment=[l]{//}, %use comment-line-style!
    morecomment=[s]{/*}{*/}, %for multiline comments
    showstringspaces=false,
    morekeywords={ abstract, event, new, struct,
        as, explicit, null, switch,
        base, extern, object, this,
        bool, false, operator, throw,
        break, finally, out, true,
        byte, fixed, override, try,
        case, float, params, typeof,
        catch, for, private, uint,
        char, foreach, protected, ulong,
        checked, goto, public, unchecked,
        class, if, readonly, unsafe,
        const, implicit, ref, ushort,
        continue, in, return, using,
        decimal, int, sbyte, virtual,
        default, interface, sealed, volatile,
        delegate, internal, short, void,
        do, is, sizeof, while,
        double, lock, stackalloc,
        else, long, static,
        enum, namespace, string},
    keywordstyle=\color{blue},
    identifierstyle=\color{black},
    backgroundcolor=\color{lightgray},
}

\DeclareCaptionFormat{listing}{\colorbox{lightgray}{\parbox{\dimexpr\linewidth-2\fboxsep}{\centering#1#2#3}}}
\captionsetup[lstlisting]{format=listing,singlelinecheck=false,margin=0pt,labelsep=colon,justification=centering}

在此处输入图片描述\usepackage{列表}

相关内容