答案1
小型入门试用(有很多选择listings
)
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\renewcommand{\ttdefault}{pcr}
\lstset{language=Java,frame=single,numbers=left,keywordstyle={\color{magenta}\bfseries},basicstyle={\small\ttfamily},commentstyle=\color{blue},showstringspaces=false}
\begin{document}
\textbf{\texttt{\bfseries Hello}}
\texttt{Hello}
\begin{lstlisting}
public class HelloWorld{
/*
Some comment
*/
public void printHelloWorld() {
System.out.println("Hello World");
}
}
\end{lstlisting}
\end{document}
以下是粗体版:
由于使用了,因此在正常的字体设置中\ttfamily
没有此字体。如果更改为(courier),则有一个粗体版本的 type writer like 字体。此外,还必须附加。bold
Computer Modern
\ttdefault
pcr
\bfseries
keywordstyle
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\renewcommand{\ttdefault}{pcr} % Change `\ttfamily` to use courier font
\lstset{language=Java,frame=single,numbers=left,keywordstyle={\color{magenta}\bfseries},basicstyle={\small\ttfamily},commentstyle=\color{blue},showstringspaces=false}
\begin{document}
\textbf{\texttt{\bfseries Hello}}
\texttt{Hello}
\begin{lstlisting}
public class HelloWorld{
/*
Some comment
*/
public void printHelloWorld() {
System.out.println("Hello World");
}
}
\end{lstlisting}
\end{document}