[Tex/LaTex] Using consolas as the default teletype style font for listings package

fontstypewriter

Is it possible to use consolas as the default teletype font to display code listings using the listings package?
The default computer modern teletype font is too wide for my taste.

Edit: I am using regular LaTeX.

Best Answer

You can use Consolas using either XeLaTeX or LuaLaTeX with the fontspec package.

If you want Consolas to be your default monospaced font for everything:

Add the following code to your preamble:

\usepackage{fontspec}
\setmonofont{Consolas}

There are other options you can pass to \setmonofont; see the fontspec documentation.

If you only want Consolas for your code listings:

Add the following code to your preamble:

\usepackage{fontspec}
\newfontfamily\Consolas{Consolas}
\lstset{basicstyle=\Consolas}

Again there are additional options you can pass to \newfontfamily.