6

I've been using the listings package for a while, but have only recently noticed that the underscore is rendered with less width than the other characters. I'm working on some code snippets now which use a lot of variables containing an underscore, and so I see the effect more than ever. Is there any way to prevent this?

8

Say

\usepackage[T1]{fontenc}

in your preamble. The default underscore in OT1 encoding is indeed quite small.

If you don't want to switch font encoding, then the following code in the preamble will produce a similar underscore:

\makeatletter
\DeclareTextCommandDefault{\textunderscore}{%
  \leavevmode\kern0.03em\vbox{\hrule\@width.6em \@height-.25ex \@depth0.37ex}\kern0.03em}
\makeatother

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.