I want to use times in headings but I want to use Consolas inside listings, however times and fontspec overrides one with another. I have tried the following:

\usepackage{times} % Use the Times font for headings
\lstdefinestyle{c++} {%
    backgroundcolor=\color{format-color!6!white}, % set backgroundcolor
    basicstyle=\footnotesize\ttfamily\color{white!10!black},% basic font setting
%... more things down

But naturally I doesn't work, my headings are print different with a different font.

I just want the Consolas font in my listings, nothing more. I would really appreciate your help.

Edit: I use my listings next way:

% In the class document
    %#1 is the file path
% In the document
  • 2
    don't use \usepackage{times} with an unicode engine. Set a times font with \setmainfont. Commented Sep 27, 2020 at 19:52
  • Please edit your posting to provide an example of how you use lstlisting environments.
    – Mico
    Commented Sep 27, 2020 at 19:55
  • @Mico I have edited the post Commented Sep 27, 2020 at 20:17


You must log in to answer this question.

Browse other questions tagged .