문제

구두 환경 내부에 쓴 코드가 있습니다. 때로는 선이 너무 길고 생성 된 PDF가 못 생겼습니다. 텍스트 행은 올바른 여백을 통과합니다. 이 긴 줄을 자동으로 깨뜨리려면 어떻게해야합니까? 동사상보다 더 좋은 것이 있습니까?

고마워요, 루시안

도움이 되었습니까?

해결책

고정형 글꼴 만 사용할 수 있습니까? \texttt{}? 더 정교한 것이 필요한 경우 시도하십시오 더 많은 사람, 목록, 또는 알고리즘 패키지.

다른 팁

물론, 당신은 훌륭한 "목록"패키지를 가지고 있습니다. 그것은 많은 소스 코드 언어를 꽤 인쇄 할뿐만 아니라 표시되는 언어에 따라 긴 줄의 "스마트 브레이킹"을 지원합니다.

이를 위해 리스팅 패키지를 사용하는 것이 좋습니다. 코드를 멋지게 포맷하고 많은 언어를 지원합니다 ( PG12), 세 가지 방법으로 효과적으로 사용됩니다.

  1. 인라인 스 니펫은 다음을 사용하여 포함됩니다 \lstinline!int x = 0;! 명령
  2. 내에서 입력 된 코드 블록 lstlisting 다음과 같은 환경

    \begin{lstlisting}
    for i:=maxint to 0 do
    begin
    { do nothing }
    end;
    \end{lstlisting}
    
  3. 예를 들어 소스 코드 파일에서 직접 문서에 코드가 내장 된 가져 오기 코드 블록. \lstinputlisting{source.py}

이 패키지로 구성 할 수있는 많은 옵션이 예를 들어 랩 라인 및 라인 번호를 포함하여 전체 세부 사항을 찾을 수 있습니다. 패키지 문서, 그러나 좋은 기본 설정이 Wikibook 출품작:

\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=2,                   % the step between two line-numbers. If it's 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
}

lgrind와 같은 예쁜 패키지를 시도 할 수 있습니다. 그렇지 않으면 줄을 수동으로 파괴해야합니다.

당신은 또한 관심을 가질 수 있습니다 FancyVRB 패키지.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top