我想使用sourcecodepro
包来排版源代码Beamer
。无论是否加载,以下代码都会提供相同的字体sourcecodepro
。我想坚持使用pdflatex
。
\documentclass[ngerman]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usefonttheme{professionalfonts}
\usepackage{sourcecodepro}
\usepackage{listings}
\begin{document}
\frame[containsverbatim]{
\frametitle{Test}
\framesubtitle{Systeme}
\begin{itemize}
\item Hello, this is a
\item test for the sourcecodepro
\item Right now it does not work
\end{itemize}
\begin{lstlisting}
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
\end{lstlisting}
}
\end{document}
答案1
加载sourcecodepro
软件包使 Source Code Pro 成为默认打字机文档的字体。但是,默认情况下,listings
包使用文档的默认字体罗马家庭。
因此,加载后sourcecodepro
,您仍然需要告诉listings
您想要用打字机字体排版您的代码:
basicstyle = \ttfamily
\documentclass[ngerman]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usefonttheme{professionalfonts}
\usepackage{sourcecodepro}
\usepackage{listings}
\begin{document}
\frame[containsverbatim]{
\frametitle{Test}
\framesubtitle{Systeme}
\begin{itemize}
\item Hello, this is a
\item test for the sourcecodepro
\item Right now it does not work
\end{itemize}
\begin{lstlisting}[basicstyle=\ttfamily] % <--- here
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
\end{lstlisting}
}
\end{document}