views:

45

answers:

2

Hi,

I'm trying to get my code snippets to look as good as possible and so far I'm having troubles with the character spacing. Here is an example of the output:

alt text

While the text in small is perfect, all the keywords that are in capital letters look terrible. Here are the settings I use

\lstset{basicstyle=\footnotesize, basewidth=0.5em}

If I increase the basewidth, the capital letters look good, but I can't get any decent sized line of code in one line. The following example does not fit in a page and I already put two line breaks in: alt text

Does anyone have a clue how I can get this to work? Using \ttfamily does the trick, however, I'd prefer keeping the font.

Thanks.

A: 

You "obviously" need to scale the capital letters down horizontally. I do not know of a way to do this without actually editing the font itself.

However, you could put the entire listing into a \scalebox resp. \resizebox (from the graphicx package).

On a side note, the font you are using seems a bit strange, though, since the distance between small letters is significantly bigger than that between capital letters.

Svante
+1  A: 

If you prioritize looking nice, then using flexible colums is preferable:

\lstset{basicstyle=\footnotesize, columns=fullflexible}
grddev