\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\lstset{language=C++}%这条命令可以让LaTeX排版时将C++键字突出显示
\lstset{breaklines}%这条命令可以让LaTeX自动将长的代码行换行排版
\lstset{extendedchars=false}%这一条命令可以解决代码跨页时,章节标题,页眉等汉字不显示的问题
\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
}
\begin{document}
\begin{lstlisting}
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
printf("helloworld!");
}
\end{lstlisting}
\end{document}
LaTeX 代码片插入语法【转】
最新推荐文章于 2024-03-08 21:32:03 发布