2010-05-26 21 views
33

這是代碼在Xcode中的樣子。 xcode http://img94.imageshack.us/img94/972/xcode.png乳膠:帶有等寬字體的清單

而這在我的清單中用texlive創建。

alt text http://img25.imageshack.us/img25/1245/latexn.png

是的,我用basicstyle = \ ttfamily。說完看着房源手冊我還沒有發現關於固定帶或等寬字體什麼..

實例再現

\documentclass[ 
    article, 
    a4paper, 
    a4wide, 
    %draft, 
    smallheadings 
]{book} 

% Packages below 
\usepackage{graphicx} 
\usepackage{verbatim} % used to display code 
\usepackage{hyperref} 
\usepackage{fullpage} 
\usepackage[ansinew]{inputenc} % german umlauts 
\usepackage[usenames,dvipsnames]{color} 
\usepackage{float} 
\usepackage{subfig} 
\usepackage{tikz} 
\usetikzlibrary{calc,through,backgrounds} 
\usepackage{fancyvrb} 
\usepackage{acronym} 
\usepackage{amsthm} % Uuhhh yet another package 
\VerbatimFootnotes % Required, otherwise verbatim does not work in footnotes! 
\usepackage{listings} 

\definecolor{Brown}{cmyk}{0,0.81,1,0.60} 
\definecolor{OliveGreen}{cmyk}{0.64,0,0.95,0.40} 
\definecolor{CadetBlue}{cmyk}{0.62,0.57,0.23,0} 
\definecolor{lightlightgray}{gray}{0.9} 

\begin{document} 
\lstset{ 
language=C,        % Code langugage 
basicstyle=\ttfamily,     % Code font, Examples: \footnotesize, \ttfamily 
keywordstyle=\color{OliveGreen},  % Keywords font ('*' = uppercase) 
commentstyle=\color{gray},    % Comments font 
numbers=left,       % Line nums position 
numberstyle=\tiny,      % Line-numbers fonts 
stepnumber=1,       % Step between two line-numbers 
numbersep=5pt,       % How far are line-numbers from code 
backgroundcolor=\color{lightlightgray}, % Choose background color 
frame=none,        % A frame around the code 
tabsize=2,        % Default tab size 
captionpos=b,       % Caption-position = bottom 
breaklines=true,      % Automatic line breaking? 
breakatwhitespace=false,    % Automatic breaks only at whitespace? 
showspaces=false,      % Dont make spaces visible 
showtabs=false,       % Dont make tabls visible 
columns=flexible,      % Column format 
morekeywords={__global__, __device__}, % CUDA specific keywords 
} 

\begin{lstlisting} 
    As[threadRow][threadCol] = A[ 
     threadCol + threadRow * Awidth // Adress of the thread in the current block 
     + i * BLOCK_SIZE     // Pick a block further left for i+1 
     + blockRow * BLOCK_SIZE * Awidth // for blockRow +1 go one blockRow down 
    ]; 
\end{lstlisting} 

\end{document} 
+2

你能提供一個最小的工作示例嗎?也就是說,只有你的'物品清單'環境和重現錯誤代碼所需的包裹。 – Pieter 2010-05-26 16:27:33

+0

Hey Nils,我認爲你的代碼很棒,我甚至可以使用Fortran 90.你是否介意將它用於我的論文? ;) – 2012-09-18 00:30:29

回答

31

問題是columns=flexible選項。刪除它,它看起來像你想看看。至少,如果沒有真正的理由讓你使用它。如果有的話,沒有辦法讓你的片段的等寬度看起來像Xcode :)。

+2

請記住使用'basicstyle = \ ttfamily',否則'columns = fixed'不起作用。 (我的情況) – 2012-04-24 21:02:09

+0

只要使用'keepspaces = true'選項,當使用'basicstyle = \ ttfamily'時,'columns = flexible'可以被保留。這將給出更「緊湊」的外觀。類似於逐字。 – 2014-02-24 23:52:56

3

當你放下\ usepackage {} microtype會發生什麼?它會產生扭曲等等,並可能是問題的原因,我認爲這是由於對齊不良。

+0

這不是很明顯嗎?我希望它使用等寬字體,以便它看起來像Xcode(使用等寬字體)。 – Nils 2010-05-26 13:33:26

+0

我在一段時間後解決了這個問題,並改變了我的答案。 – 2010-05-26 14:24:45

+0

這不應該是問題,微型手冊在第9章:提示和警告中指出,它與fancyvrb和'listings'很好地協同工作。當他顯示'lstset'時,我認爲他使用這個代碼清單:)。 – Pieter 2010-05-26 16:26:05