2

I'm using listings to display code in my document and tgheros font. How can I decrease the monotype letter spacing for code listings?

% in my preamble
\usepackage{listings}
\usepackage{tgheros}

% lstset definition
\lstset{language=Python,%
    basicstyle=\ttfamily\small,%
    % [...]
}

% code
Python code below.

\lstset{language=Python}
\begin{lstlisting}
def function(variable):
    pass # monospace font spacing is too large
\end{lstlisting}

In the screenshot you can see that the letter spacing is quite high. How to decrease it while keeping a monospace font?

screenshot

0

1 Answer 1

7

Use the basewidth setting in your lstset definition:

\lstset{language=Python,%
    basicstyle=\ttfamily\small,%
    basewidth=0.6em % default value
}

For example, basewidth=0.6em (default):

enter image description here

basewidth=0.5em

enter image description here

1

You must log in to answer this question.

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