0

I am writing a document in Latex (pdflatex) and I am bound to use a predefined custom style. Now, I want/need to print a code listing using \lstlisting, which I need to be monospaced sans-serif.

My problem is now, that listings I create are monospaced, but NOT sans-serif. Whatever I try, my listings end up being serif. And I need to change that.

The style is extensive (more than 1500 lines) and must not be altered, hence pasting it in its entirety is I guess not helping.

Anyhow I went though it and think I identified the interesting parts:

\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage{lmodern,textcomp}
\RequirePackage{microtype}
\RequirePackage[ngerman]{babel}
\RequirePackage{ae,pifont}              
\Requirepackage{courier}

% ...

\usepackage{listings}
\lstloadlanguages{
    [Visual]Basic,
    Pascal,
    C,
    [ISO]C++,
    XML,
    HTML,
    Java,
    bash
}
\lstset{
    breakatwhitespace=false,
    upquote=true,
    keepspaces=true,
    language=Java,
    numbers=none,
    numbersep=5pt,
    tabsize=2,
    extendedchars=true,
    breaklines=true,
    basicstyle=\scriptsize\ttfamily\color{basicStyleColor},
    identifierstyle=\color{identifierStyleColor},
    keywordstyle=[1]\color{keywordStyle1Color},
    keywordstyle=[2]\color{keywordStyle2Color},
    keywordstyle=[3]\color{keywordStyle3Color},
    stringstyle=\color{stringStyleColor},
    commentstyle=\itshape\color{commentStyleColor},
    numberstyle=\tiny\color{commentStyleColor},
    rulecolor=\color{black},
    showspaces=false,
    showtabs=false,
    xleftmargin=17pt,
    frame=none,
    framexleftmargin=17pt,
    %framexrightmargin=5pt,
    framexbottommargin=4pt,
    %backgroundcolor=\color{lightgray},
    showstringspaces=false,
      {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
      {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1
      {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1
      {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1
      {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
      {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
      {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
      {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1
      {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1
      {ű}{{\H{u}}}1 {Ű}{{\H{U}}}1 {ő}{{\H{o}}}1 {Ő}{{\H{O}}}1
      {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
      {€}{{\euro}}1 {£}{{\pounds}}1 {«}{{\guillemotleft}}1
      {»}{{\guillemotright}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1
      {€}{{\texteuro}}1
}

with the document preamble being

\documentclass[12pt]{mystyle}

\usepackage{ulem}
\usepackage{enumerate}

\begin{document}
    \sloppy

Now, I want to print something like this and want it to be in sans-serif font:

\begin{lstlisting}
import akka.actor.{ActorSystem, Props}

object Main extends App {
}
\end{lstlisting}

But no matter what I do, the font always remains the same for the listings.

How do I change the font for the listings (Meaning: not just the font-family (\tttype), but the entire font?) while at the same time NOT changing the font for the rest of the document?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.