LaTeX技巧007:设置插入代码的样式

Java


LaTeX技巧007:设置插入代码的样式_第1张图片

\documentclass[a4paper,UTF8]{article}
\usepackage{listings}
\usepackage{color}
\usepackage{fontspec}
\newcommand{\tnewroman}{\fontspec{Times New Roman}}
\definecolor{keywordcolor}{rgb}{0.8,0.1,0.5}
\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{bgcolor}{rgb}{0.92,0.92,0.92}
\lstset{language=[AspectJ]Java,
    %backgroundcolor=\color{bgcolor}, 设置背景色
    basicstyle=\large,
    keywordstyle=\color{keywordcolor}\bfseries, %关键字设置
    identifierstyle=,
    commentstyle=\color{blue} \textit, %注释设置
    showstringspaces=false,
    captionpos=b,
    xleftmargin=2em,
    xrightmargin=2em, 
    aboveskip=1em
    %frame=shadowbox,%设置是否有边框[single/shadowbox]
    %numbers=left, 设置显示行号在左边
    %numberstyle=\large 行号的字体
}
\begin{document}
\tnewroman
\begin{lstlisting}
public int sum(int n){
    int sum = 0;
    for(int i=0;i
    return sum;
}
\end{lstlisting}
\end{document}

你可能感兴趣的:(LaTeX)