Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Related Question: Getting incorrect underscores from macro in an lstlisting. –  Peter Grill Nov 17 '12 at 5:35
add comment

1 Answer

up vote 7 down vote accepted

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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