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 use the following settings for my listings:

\lstset{
  %basicstyle=\ttfamily\tiny, % small
  basicstyle=\ttfamily\scriptsize, % middle
}

But the font in the listings is too bold for me. I tried a lot of things, but I couldn't change it.

I want to use a monospace (fixed) font in my listings, is there any other font I could use?

PS: I compile my tex files with a xelatex compiler.

EDIT #2:

Complete example:

\documentclass[12pt,german,a4paper]{scrreprt}

\usepackage{xltxtra}
\usepackage{lmodern}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{listings}

\begin{document}
\lstset{
    basicstyle=\ttfamily\scriptsize, % bold and monospace
    %basicstyle=\scriptsize, % not bold and not monospace
}
\pagestyle{plain}
\begin{lstlisting}
cntNodes++;
nodes = (DG_NODE_ID *) realloc(nodes, cntNodes * sizeof (DG_NODE_ID));
if (nodes == NULL) {
    fprintf(stderr, "Error: No memory left!\n");
    return false;
} /* if */
\end{lstlisting}
\end{document}
share|improve this question
    
Make a complete example so that we can see what you use as default typewriter. –  Ulrike Fischer Mar 14 '13 at 10:08
    
Remove the packages xltxtra, lmodern, xunicode. Then make a complete example. –  Ulrike Fischer Mar 14 '13 at 10:14
    
So now it is really complete, I ensured also that it compiles. –  MeJ Mar 14 '13 at 11:50
add comment

2 Answers 2

up vote 6 down vote accepted

scale down the monospace font or use flexible colums or define a smaller letter space (see package fontspec). SourceCodePro is part of TL2012.

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Calibri}
\setmonofont[Scale=0.95,
%             FakeStretch=0.8,
             Mapping=tex-text]{SourceCodePro-Regular.otf}
\newfontface\SmallMono[FakeStretch=0.8,
                       Mapping=tex-text]{SourceCodePro-Regular.otf}
\usepackage{listings}
\usepackage{lipsum}

\lstset{
  basicstyle=\ttfamily\small, % middle
  columns=flexible
}
\begin{document}

\lipsum[1]
\begin{lstlisting}
\directlua{securityproblem("\today")}
\end{lstlisting}

\lstset{
  basicstyle=\SmallMono\small,
  columns=flexible}
\begin{lstlisting}
\directlua{securityproblem("\today")}
\end{lstlisting}

\end{document}

enter image description here

share|improve this answer
    
In PdfLatex I use a command \newcommand*\lstfont{\ttfamily\hyphenchar\font\m@ne\@noligs} to ensure that a proper minus sign "-" and not a rule is used (some fonts) in listings. How do I enforce the same thing in the example above? For example put y = --x in your source code and see the effect in the second listing. –  Danie Els Mar 14 '13 at 11:42
1  
@DanieEls: Simply don't use the Mapping=tex-text for the typewriter font. –  Ulrike Fischer Mar 14 '13 at 12:23
    
or literate={-}{{\char"02D}}1 with \lstset –  Herbert Mar 14 '13 at 13:04
    
So I just added following line: \setmonofont[Scale=0.95]{SourceCodePro-Regular.otf} and now it works for me. –  MeJ Mar 14 '13 at 13:52
6  
@Herbert Since you're not a chat regular, I'd like to congratulate you here for your big achievement: reaching 100k rep might not mean much (it does, indeed), but at least it gives an occasion for thanking you for your big contribution to the TeX world. –  egreg Mar 15 '13 at 20:59
show 2 more comments

If you put \usepackage{times} in your preamble, that will switch your monospace font to Courier, which is somewhat thinner than Computer Modern.

Alternatively, if you just put \renewcommand{\ttdefault}{pcr} in your preamble, that will switch your monospace font to Courier, but will not affect your other fonts.

You can also use \lstset{basicstyle=\fontfamily{pcr}\selectfont\scriptsize} to change the font to Courier temporarily.

share|improve this answer
    
But if I use your package, my headers will be also displayed thinner. I just want to change the font in the listings. And the font will not be displayed in monospace. –  MeJ Mar 14 '13 at 9:40
    
If i just use: basicstyle=\scriptsize it is okay for me, but it isn't monospace. –  MeJ Mar 14 '13 at 9:47
1  
This won't work with xelatex. –  Ulrike Fischer Mar 14 '13 at 10:06
    
I added some more information in my initial post! –  MeJ Mar 14 '13 at 10:12
    
By loading the times package, you will also change the main text font from Latin Modern to Times Roman -- in addition to changing the monospaced font to Courier. The change to Times Roman text fonts may not be to the OP's liking. –  Mico Mar 14 '13 at 16:55
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.