Hãy thử một cái gì đó như thế này:
\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}
trong đó sản xuất:
alt text http://img260.imageshack.us/img260/1608/codes.png
Nguồn
2010-04-22 12:54:45
làm cách nào để lấy latex thoát ra và \ n tự động? – KP65
ok cảm ơn, chỉnh sửa op – KP65
Một lưu ý thẩm mỹ: cột = cố định thường cho kết quả xấu (như ở đây, các chữ cái được đặt cách nhau quá nhiều). Tôi thích các cột = fullflexible, ngay cả với một phông chữ cố định chiều rộng, nó cho một cái nhìn tự nhiên hơn nhiều để mã. –