答案1
您的示例显示了代码的固定字体。使用包
ffcode
可能是一种方法。
\documentclass{article}
\usepackage{ffcode}
\begin{document}
\begin{ffcode}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{ffcode}
\end{document}
带包装minted
不过,你可以有多个带有彩色字符的主题。请注意,我还使用
xcolor
vim
由于人物不太容易被看到,因此不适合该主题的包装 。
\documentclass{article}
\usepackage{minted}
\usepackage{xcolor}
\colorlet{myblack}{black!50!white}
\begin{document}
\section*{Minted styles with non-italic comments}
\subsection*{Light theme}
\subsubsection*{\texttt{perldoc}}
\usemintedstyle{perldoc}
\begin{minted}[linenos]{r}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{minted}
\subsubsection*{\texttt{rrt}}
\usemintedstyle{rrt}
\begin{minted}[linenos]{r}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{minted}
\subsubsection*{\texttt{pastie}}
\usemintedstyle{colorful}
\begin{minted}[linenos]{r}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{minted}
\subsubsection*{\texttt{colorful}}
\usemintedstyle{colorful}
\begin{minted}[linenos]{r}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{minted}
\subsubsection*{\texttt{vs}}
\usemintedstyle{vs}
\begin{minted}[linenos]{r}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{minted}
\subsection*{Dark theme}
\subsubsection*{\texttt{vim}}
\usemintedstyle{vim}
\begin{minted}[bgcolor=myblack,linenos]{r}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{minted}
\subsubsection*{\texttt{monokai}}
\usemintedstyle{monokai}
\begin{minted}[bgcolor=black,linenos]{r}
set.seed(123)
## do grid
y <- rcoga(100000, c(2, 5, 7), c(3, 2, 4))
grid <- seq(0,15,length.out=100)
## calculate pdf and cdf
\end{minted}
笔记:要使用这些包中的任何一个,您需要在终端中安装python3-pygments
包并调用 标志,如下所示。--shell-escape
pdflatex --shell-escape filename.tex