我正在使用Latex编写列出我所有代码的程序,我遵循这个:
http://texblog.wordpress.com/2008/04/02/include-source-code-in-latex-with-listings/
它工作正常,但我的代码运行在页面的一侧.我怎样才能解决这个问题?附加问题:如何让它突出显示语法?我确实把lang设置为Java.
尝试这样的事情:
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
language=c,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fullflexible,
showstringspaces=false,
extendedchars=true,
breaklines=true,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}
\begin{document}
\begin{lstlisting}
#include <stdio.h>
int main()
{
// A line comment
printf("A really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, really, REALLY long line. && & \n");
return 0;
}
\end{lstlisting}
\end{document}
Run Code Online (Sandbox Code Playgroud)
产生:
alt text http://img260.imageshack.us/img260/1608/codes.png
归档时间: |
|
查看次数: |
4534 次 |
最近记录: |