尝试了 Python 代码颜色编码包,当我这样做时,整个文档中的字体突然开始变得奇怪。s、a、o 和其他一些字母的排版比其他字母大,整个文本看起来很奇怪。有人有什么想法吗?
\documentclass{article}
\usepackage[swedish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[procnames]{listings}
\usepackage{color}
\begin{document}
\definecolor{keywords}{RGB}{255,0,90}
\definecolor{comments}{RGB}{0,0,113}
\definecolor{red}{RGB}{160,0,0}
\definecolor{green}{RGB}{0,150,0}
\lstset{language=Python,
basicstyle=\ttfamily\small,
keywordstyle=\color{keywords},
commentstyle=\color{comments},
stringstyle=\color{red},
showstringspaces=false,
identifierstyle=\color{green},
procnamekeys={def,class}}
\title{Python}
\author{Some guy}
\maketitle
\newpage
\section{Objektorientering}
Såhär skapar man en klass i Py:
\begin{lstlisting}
class Employee:
empCount = 0 # kommer shareas av alla instanser
def __init__(self, name, salary):
self.name = name
self.salary = salary
Employee.empcount += 1
def displayEmployee(self):
print "Name : " self.name, "Salary: ", self.salary
\end{lstlisting}
\lstinline|__init__| är klasskonstruktorn som anropas varje gång man skapar en ny instans.
\end{document}