gpt4 book ai didi

Latex + 源代码导入

转载 作者:行者123 更新时间:2023-12-04 16:37:23 26 4
gpt4 key购买 nike

我正在使用 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}

它产生:

alt text http://img260.imageshack.us/img260/1608/codes.png

关于Latex + 源代码导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2690843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com