views:

886

answers:

3

This is what the code looks in Xcode. xcode

And this in my listing created with texlive.

alt text

And yes I used basicstyle=\ttfamily . Having looked at the manual of listings I haven't found anything about fixed-with or monospace fonts..

Example to reproduce

\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}
A: 

Are you using the Verbatim package? Show us the latex code..

bill duncan
He's using the listings package.
Charles Stewart
+2  A: 

What happens when you drop \usepackage{microtype}? It messes with kerning and so forth and might be the cause of the problem, which I assume is due to the poor alignment.

supercooldave
Isn't that obvious? I want it to use a monospace font, so that it looks like in Xcode (which uses a monospace font).
Nils
I worked it out after a while, and changed my answer.
supercooldave
That shouldn't be the problem, the microtype manual states in Chapter 9: Hints and Caveats that it works together nicely with `fancyvrb` and `listings`. As he shows a `lstset` I presume he uses listings for this code :).
Pieter
Could it be a tabs vs spaces problem, then?
supercooldave
The leading spaces on the indented lines seem to be the problem indeed. The rest of the text seems to be monospace as wanted. Are these spaces or tabs?
Pieter
@Pieter I said listing in the question..
Nils
Text is just spaces, no tabs used. I checked this twice.. And dropping microtype has no effect. But thx for trying to help so far.
Nils
+2  A: 

The problem is the columns=flexible option. Remove it and it looks like you want it to look. At least, if there is no actual reason for you to use it. If there is, there is no way to have the monospaceness of your snippet to look like in Xcode :).

Pieter
Thanks a LOT!!! I completely missed that..
Nils

related questions