本主题的目的是创建一个我们可以共享设置的公共场所listings.sty
。因此我们可以将其用作参考。
请注意,我只对以下设置感兴趣:
- 字体系列、字体大小、字体粗细、字体颜色
- 背景颜色
换句话说,这里不必考虑框架、行号等布局。
游戏规则:
使用以下代码片段作为模板。仅修改标有
%<==
。笔记:请保持字体大小不变。我已将其设置为\scriptsize
。\documentclass[dvips,dvipsnames]{article} \usepackage[a4paper,margin=55mm]{geometry} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{listings} \lstset% {% language={[Sharp]C}, breaklines=true, breakindent=0pt, tabsize=2, showstringspaces=true } %================================= %Rule of the Game: %You are ONLY allowed to %modify the lines marked with %<== %================================= \usepackage[rgb]{xcolor}%<== \lstset {% backgroundcolor=% \color{Black},%<== % basicstyle=\scriptsize%leave the font size unchanged please. \color{lightgray}\ttfamily,%<== % keywordstyle=% \color{Orange}\sffamily,%<== % commentstyle=% \color{Green},%<== % identifierstyle=% \color{Cyan},%<== % stringstyle=% \color{Yellow}%<== } \begin{document} \begin{lstlisting} using System; public class Foo { public static void Main() { Console.WriteLine("I Love LaTeX");//This is a comment. } /*This is a comment too.*/ } \end{lstlisting} \end{document}
以 150% 的比例查看 pdf 输出,并以 *.png 格式对其进行截图。
- 提交您的截图,然后提交您修改后的设置(请不要提交完整的代码)。您可以提交任意数量的截图,但请确保不要重复。
答案1
我更喜欢更简单的设计,无论是在网络上还是在印刷品上。太多的颜色会让读者感到困惑,用 Bringhurst 的话来说,这是一种intrusion
。
重点突出讨论的重点,而不是整个代码。代码必须像段落一样阅读!另外,我更喜欢一般环境,而不是单独的宏,所以这里是我的极简主义!
\gdef\emphasis#1{\lstset{emph={write,void,writeln,#1},
emphstyle={\itshape\ttfamily\textcolor{blue}}}}
\lstnewenvironment{teXXX}[1][]
{\lstset{language=[LaTeX]TeX}\lstset{%
breaklines=true,
framesep=5pt,
basicstyle=\normalsize\ttfamily,
showstringspaces=false,
keywordstyle=\itshape,
stringstyle=\color{maroon},
commentstyle=\color{black},
rulecolor=\color{Gray},
xleftmargin=0pt,
xrightmargin=5pt,
aboveskip=\medskipamount,
belowskip=\medskipamount,
backgroundcolor=\color{LightGray!5}, #1
}}
{}
答案2
黑暗中的霓虹
\usepackage[rgb]{xcolor}%<==
\lstset
{%
backgroundcolor=%
\color{Black},%<==
%
basicstyle=\scriptsize%
\color{lightgray}\ttfamily,%<==
%
keywordstyle=%
\color{Orange}\sffamily,%<==
%
commentstyle=%
\color{Green},%<==
%
stringstyle=%
\color{Yellow}%<==
}
答案3
经典 Turbo Pascal(不是 100% 确定)
\usepackage[cmyk]{xcolor}%<==
\lstset
{%
backgroundcolor=%
\color{Blue},%<==
%
basicstyle=\scriptsize%
\color{White}\ttfamily,%<==
%
keywordstyle=%
\color{Yellow}\sffamily,%<==
%
commentstyle=%
\color{Red},%<==
%
stringstyle=%
\color{Green}%<==
}
答案4
淡黄色
\usepackage[rgb]{xcolor}%<==
\lstset
{%
backgroundcolor=%
\color{Yellow!20},%<==
%
basicstyle=\scriptsize%
\color{black}\ttfamily,%<==
%
keywordstyle=%
\color{blue!80}\sffamily,%<==
%
commentstyle=%
\color{OliveGreen},%<==
%
stringstyle=%
\color{red}%<==
}