有没有办法让代码左侧的行号与代码使用相同的字体?我相信如果你更改代码的默认字体,行号仍然是默认字体。我正在使用该listings
包并更改为 Deja Vu Sans Mono 字体。
\documentclass[11pt,a4paper]{article} \usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[onehalfspacing]{setspace}
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{DejaVuSansMono}
\usepackage{listings}
\lstset{frame=tb,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\footnotesize\ttfamily},
numbers=left,
numbersep=0pt,
numberstyle=\tiny\color{gray},
breaklines=true,
breakatwhitespace=true,
tabsize=3
}
\begin{document}
\begin{lstlisting}
Hello
Hello
Hello
\end{lstlisting}
\end{document}
答案1
只需添加\ttfamily
到您的设置中\numberstyle
:
\documentclass{article}
\usepackage{xcolor}
\usepackage{DejaVuSansMono}
\usepackage{listings}
\lstset{frame=tb,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\footnotesize\ttfamily},
numbers=left,
numbersep=1ex,
numberstyle={\tiny\color{gray}\ttfamily},
breaklines=true,
breakatwhitespace=true,
tabsize=3
}
\begin{document}
\begin{lstlisting}
Hello
Hello
Hello
\end{lstlisting}
\end{document}