Does anyone know why I'm getting extra spaces in front of the keywords in my code listings? I've attached a picture of one of my listings that I've compile with showspaces=true and showtabs=true. You can clearly see gaps in front of the void, range, int, and other keywords. However these gaps aren't denoted as being spaces with the underscoring.

The styles I'm using are:


Also there are no spaces in front of any of the keywords in the keywords={ or morekeywords={ sections of my language definition.

Is it something to do with the change in font families between the keywords and regular identifiers? Does anyone have any suggestions how I can get rid of them?

Example of code listing with extra spaces


1 Answer 1


In the process of trying to create a minimum working example I managed to track down the problem. Initially I couldn't reproduce the glitch. It's not actually connected to the Listings package, but rather other header statements in my thesis.

Some microtype compilation code that I'd come across in a blog post by Cameron Bracken was the real culprit.

The troublesome section was:


In particular it seems like the indentation in Cameron's example between the @font{ and the \MT@exp@one.... was the problem. If you remove the carriage return (or new line) and place both statements on a single line the problem disappears from any listings.

  • 1
    90% of all questions with the word "space" in them are answered by adding % to ends of line. Commented Aug 6, 2013 at 15:16
  • I think I was wrong-footed by the fact the issue only revealed itself in code listings, so it wasn't particularly obvious that actually the microtype stuff was to blame. Ach well, the joys of LaTeX!
    – Alastair
    Commented Aug 6, 2013 at 15:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .