質問

逐語的環境内で記述するコードがいくつかあります。場合によっては、行が長すぎて、生成された PDF が見苦しくなり、テキスト行が右マージンを超えてしまうことがあります。このような長い行を自動的に改行するにはどうすればよいでしょうか?逐語的な env よりも優れたものはありますか?

ありがとう、ルシアン

役に立ちましたか?

解決

固定幅フォントを使用できますか? \texttt{}?より洗練されたものが必要な場合は、次の方法を試してください。 もっと動詞, リスト, 、 または アルゴリズムx パッケージ。

他のヒント

もちろん、あなたはそのための素晴らしい「リスト」のパッケージを持っています。 (必要に応じ)それは表示されているソースコードの言語の多くのも、かなりの印刷だけでなく、言語に応じて長い行の「スマート破壊」をサポートしています。

そのためにはリスティングパッケージを利用することを強くお勧めします。コードを適切にフォーマットし、多数の言語をサポートします (「 Pg12)、次の 3 つの方法で効果的に使用されます。

  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}

このパッケージには、行を折り返す、行番号を含めるなど、非常に多くのオプションを設定できます。詳細については、 パッケージのドキュメント, ただし、優れた基本セットアップは、 ウィキブックのエントリ:

\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のようなきれいな印刷パッケージを試みることができます。そうしないと、手動でする必要があります 行を分割ます。

scroll top