编码格式化(C语言)

编码格式化(C语言)

我有一个 C 语言代码。我希望将边距数字和符号(例如 (, )、{, }、=、> 等)设置为白色。我正在使用以下格式工作,但没有任何实际结果。

\usepackage{listings} %CODE STYLE 
\usepackage{color}

\definecolor{red}{rgb}{0.6,0,0} 
\definecolor{blue}{rgb}{0,0,0.6}
\definecolor{green}{rgb}{0,0.8,0}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}
\definecolor{cloudwhite}{rgb}{0.9412, 0.9608, 0.8471} 
\definecolor{davysgrey}{rgb}{0.33, 0.33, 0.33}
\definecolor{deepfuchsia}{rgb}{0.76, 0.33, 0.76}
\definecolor{deepskyblue}{rgb}{0.0, 0.75, 1.0}

\lstset{
    language=csh,
    basicstyle=\footnotesize\ttfamily,
    numbers=left,
    numberstyle=\tiny,
    numbersep=5pt,
    tabsize=2,
    extendedchars=true,
    breaklines=true,
    frame=b,
    stringstyle=\color{white}\ttfamily,
    showspaces=false,
    showtabs=false,
    xleftmargin=17pt,
    framexleftmargin=17pt,
    framexrightmargin=5pt,
    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{deepfuchsia},
    identifierstyle=\color{deepskyblue},
    backgroundcolor=\color{davysgrey},
}

结果是这样的:

在此处输入图片描述

我的理想代码格式需要与这个深色主题接近。

在此处输入图片描述

答案1

对于白线号码:numberstyle=\tiny\color{white},

不过,我想知道如果您想显示 C 代码,为什么要使用 csh shell 的样式?

\documentclass{article}

\usepackage{listings} %CODE STYLE 
\usepackage{color}

\definecolor{red}{rgb}{0.6,0,0} 
\definecolor{blue}{rgb}{0,0,0.6}
\definecolor{green}{rgb}{0,0.8,0}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}
\definecolor{cloudwhite}{rgb}{0.9412, 0.9608, 0.8471} 
\definecolor{davysgrey}{rgb}{0.33, 0.33, 0.33}
\definecolor{deepfuchsia}{rgb}{0.76, 0.33, 0.76}
\definecolor{deepskyblue}{rgb}{0.0, 0.75, 1.0}

\lstset{
    language=csh,
    basicstyle=\footnotesize\ttfamily,
    numbers=left,
    numberstyle=\tiny\color{white},
    numbersep=5pt,
    tabsize=2,
    extendedchars=true,
    breaklines=true,
    frame=b,
    stringstyle=\color{white}\ttfamily,
    showspaces=false,
    showtabs=false,
    xleftmargin=17pt,
    framexleftmargin=17pt,
    framexrightmargin=5pt,
    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{deepfuchsia},
    identifierstyle=\color{deepskyblue},
    backgroundcolor=\color{davysgrey},
}

\begin{document}
\begin{lstlisting}
fkelc
eqer
()
\end{lstlisting}
\end{document}

\end{document}

相关内容