gpt4 book ai didi

latex - 让 LaTeX 中的代码看起来*漂亮*

转载 作者:行者123 更新时间:2023-12-03 04:29:24 37 4
gpt4 key购买 nike

我目前正在编写一份项目报告,为了解释我使用的有点疯狂的、不直观的代码,我需要放入大量示例代码的简短摘录。

如何将代码导入 LaTeX:

  • 看起来不错
  • 如果行太长(列表列表或逐字),也不会超出页面的一侧
  • 最好与文本的其余部分内联

已编辑(我想添加这些设置,这样人们就不必尝试自己弄清楚它们(取自维基教科书(向下链接)并进行编辑以便美观))

不错的设置:

\usepackage{color}
\usepackage{listings}
\lstset{ %
language=C++, % choose the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\footnotesize, % the size of the fonts that are used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1 each line will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
frame=single, % adds a frame around the code
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
escapeinside={\%*}{*)} % if you want to add a comment within your code
}

\begin{lstlisting}
!!code!!
\end{lstlisting}

这些设置的示例:

最佳答案

listings包非常好而且非常灵活(例如注释和代码的不同大小)。

关于latex - 让 LaTeX 中的代码看起来*漂亮*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/586572/

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