\documentclass[11pt,a4paper]{article} \usepackage{xltxtra} \usepackage{fontspec} \usepackage{float} \usepackage{listings} \usepackage{xcolor} \usepackage{color} \usepackage[top=0.8in,bottom=0.8in,left=1.2in,right=0.6in]{geometry} \lstset{ language=[ANSI]c, basicstyle=\small, numbers=left, keywordstyle=\color{blue}, numberstyle={\tiny\color{lightgray}}, stepnumber=1, %行号会逐行往上递增 numbersep=5pt, commentstyle=\small\color{red}, backgroundcolor=\color[rgb]{0.95,1.0,1.0}, showspaces=false, showtabs=false, frame=shadowbox, framexleftmargin=5mm, rulesepcolor=\color{red!20!green!20!blue!20!}, % frame=single, % TABframe=single, tabsize=4, breaklines=tr, extendedchars=false %这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题 } %字体 \setmainfont[BoldFont={SimHei},ItalicFont={KaiTi}]{SimSun} \setsansfont[BoldFont=SimHei]{KaiTi} \setmonofont{NSimSun} %%设置中文 %中文断行 \XeTeXlinebreaklocale "zh" \XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt \begin{document} 此页故意留作空白 \newpage \subsection{LaTex汉字测试} 测试文件 \lstinputlisting{src/function.h} \lstinputlisting{src/function.c} \begin{lstlisting} int main(int argc, char ** argv) { /* 测试汉字注释 */ printf("Hello world!\n"); return 0; } \end{lstlisting} \end{document}