라텍스 모양 * 니스 * [닫기]로 코드를 만듭니다.
문제
현재 프로젝트 보고서를 작성하고 있으며 내가 사용한 약간 미친 직관적 인 코드를 설명하기 위해 예제 코드의 짧은 발췌를 많이 넣어야합니다.
라텍스에 코드를 얻는 방법 :
- 멋져 보인다
- 라인이 너무 길면 페이지 옆에서 벗어나지 않습니다 (list listlisting 또는 verbatim)
- 바람직하게는 나머지 텍스트와 인라인입니다
편집 됨 (사람들이 스스로 스스로 알아낼 필요가 없도록 설정을 추가했다고 생각했습니다 (Wikibooks에서 가져와 링크를 링크하고 Nicefeness를 위해 편집).
좋은 설정 :
\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}
이러한 설정의 예 :
해결책
그만큼 목록 패키지는 매우 훌륭하고 매우 유연합니다 (예 : 주석 및 코드의 크기가 다릅니다).
다른 팁
그것은 그게 밝혀졌습니다 lstlisting
코드를 멋지게 포맷 할 수 있지만 많은 조정이 필요합니다.
Wikibooks 조정할 수있는 매개 변수에 대한 좋은 예가 있습니다.
간단한 문서의 경우 때로는 구두를 사용하지만 목록은 큰 코드 덩어리에 좋습니다.
제휴하지 않습니다 StackOverflow