![将 sourcecodepro 字体与 Beamer 列表结合使用](https://linux22.com/image/302893/%E5%B0%86%20sourcecodepro%20%E5%AD%97%E4%BD%93%E4%B8%8E%20Beamer%20%E5%88%97%E8%A1%A8%E7%BB%93%E5%90%88%E4%BD%BF%E7%94%A8.png)
我想使用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}