Latex中插入C代码

来源:互联网 发布:c语言函数查询 编辑:程序博客网 时间:2024/04/28 23:26

用LaTeX写论文时,插入C++源代码有专门的宏包,方法如下:

/usepackage{listings}

/lstset{language=C++}%这条命令可以让LaTeX排版时将C++键字突出显示

/lstset{breaklines}%这条命令可以让LaTeX自动将长的代码行换行排版

/lstset{extendedchars=false}%这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题

/begin{lstlisting}

%paste your C++ code here

/end{lstlisting}

 

下面是我常用的设置:

 

/lstset{                        %Settings for listings package.
language=[ANSI]{C},
backgroundcolor=/color{lightgray},
basicstyle=/footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=/color{olive},
directivestyle=/color{blue},
extendedchars=false,
% frame=single,%shadowbox
framerule=0pt,
keywordstyle=/color{blue}/bfseries,
morekeywords={*,define,*,include...},
numbersep=5pt,
rulesepcolor=/color{red!20!green!20!blue!20},
showspaces=false,
showstringspaces=false,
showtabs=false,
stepnumber=2,
stringstyle=/color{purple},
tabsize=4,
title=/lstname
}

zz from: http://hi.baidu.com/yangyingchao/blog/item/bbe608870a6be722c65cc33e.html

原创粉丝点击