我想知道如何将单字体设置为 Source Code Pro Light。
使用下面给出的代码,ttfamily
给出以下结果:
这是我当前拥有的代码:
\documentclass{book}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[numbered,framed]{matlab-prettifier}
\usepackage{filecontents}
\usepackage{sourcecodepro}
\usepackage{avant}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\setmonofont{Source Code Pro Light}[
BoldFont=Source Code Pro,%
Scale=MatchLowercase
]
\newcommand{\codetextcol}[2]{{\footnotesize{\ttfamily{\textcolor{#1}{#2}}}}}
\newcommand{\codetext}[1]{{\footnotesize{\ttfamily{#1}}}}
\usepackage{fourier}
\renewcommand{\ttdefault}{cmtt}
\begin{filecontents*}{\jobname.m}
% detect if next step is an obstacle
if bug.isoccupied(robot + [dx; dy])
bug.message('(%d,%d) obstacle!', n);
bug.H(bug.j,:) = robot; % define hit point
bug.step = 2;
% get a list of all the points around the obstacle
bug.edge = edgelist(bug.occgridnav == 0, robot);
%bug.k = 2; % skip the first edge point, we are already there
bug.k = size(bug.edge,2)
else
n = robot + [dx; dy];
end
end % step 1
\end{filecontents*}
\begin{document}
The Header of the ARFF file contains the name of the relation (\codetextcol{blue}{@RELATION})\index{arff syntax!"@relation}, (\codetextcol{blue}{@relation}) a list of the attributes (\codetextcol{blue}{@ATTRIBUTE})\index{arff syntax!"@attribute} (the columns in the data), and their types. Note that \codetextcol{blue}{@RELATION}, \codetextcol{blue}{@ATTRIBUTE} and \codetextcol{blue}{@DATA}\index{arff syntax!"@data} are case insensitive.
\lstinputlisting[%firstline = 236,
backgroundcolor=\color{blue!10},
style=Matlab-editor,
basicstyle=\ttfamily\scriptsize,
caption={[First Change to the Bug2 Algorithm]{First Change to the Bug2 Algorithm}},
label = mat:line246]{\jobname.m}
\end{document}
答案1
假设你使用 LuaLaTeX 或 XeLaTeX(否则为什么要使用该\setmonofont
指令?)来编译你的文档,我建议你
删除指令
\usepackage[T1]{fontenc}
和\renewcommand{\ttdefault}{cmtt}
(因为后一个命令将“电传打字机”或等宽字体更改为 Computer Modern Teletype)和\usepackage{fontspec}
在 之前立即添加指令\setmonofont{Source Code Pro Light}[...]
。
filecontents
另外,为了使用环境,已经需要加载包好几年了filecontents
。
顺便说一句,\ttfamily
不接受用花括号分隔的参数。
% !TEX TS-program = lualatex
\documentclass{book}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[numbered,framed]{matlab-prettifier}
%%%\usepackage{filecontents}
\usepackage{sourcecodepro} % <-- probably not needed
\usepackage{avant}
\usepackage{microtype}
\usepackage{lipsum}
%%%\usepackage[T1]{fontenc}
\usepackage{fontspec} % <-- new
\setmonofont{Source Code Pro Light}[
BoldFont=Source Code Pro,%
Scale=MatchLowercase
]
\newcommand{\codetextcol}[2]{%
{\footnotesize\ttfamily\textcolor{#1}{#2}}}
\newcommand{\codetext}[1]{{\footnotesize\ttfamily #1}}
\usepackage{fourier}
%%%\renewcommand{\ttdefault}{cmtt}
\begin{filecontents*}{\jobname.m}
% detect if next step is an obstacle
if bug.isoccupied(robot + [dx; dy])
bug.message('(%d,%d) obstacle!', n);
bug.H(bug.j,:) = robot; % define hit point
bug.step = 2;
% get a list of all the points around the obstacle
bug.edge = edgelist(bug.occgridnav == 0, robot);
%bug.k = 2; % skip the first edge point, we are already there
bug.k = size(bug.edge,2)
else
n = robot + [dx; dy];
end
end % step 1
\end{filecontents*}
\begin{document}
\noindent
The Header of the ARFF file contains the name of the relation (\codetextcol{blue}{@RELATION})\index{arff syntax!"@relation}, (\codetextcol{blue}{@relation}) a list of the attributes (\codetextcol{blue}{@ATTRIBUTE})\index{arff syntax!"@attribute} (the columns in the data), and their types. Note that \codetextcol{blue}{@RELATION}, \codetextcol{blue}{@ATTRIBUTE} and \codetextcol{blue}{@DATA}\index{arff syntax!"@data} are case insensitive.
\lstinputlisting[%firstline = 236,
backgroundcolor=\color{blue!10},
style=Matlab-editor,
basicstyle=\ttfamily\scriptsize,
caption={[First Change to the Bug2 Algorithm]{%
First Change to the Bug2 Algorithm}},
label = mat:line246]{\jobname.m}
\end{document}