1

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

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.