默认情况下,LaTeX 会将等宽文本设置为比默认的衬线(“罗马”)文本更大。选择自定义字体时,这一点尤其明显,例如
\usepackage{fouriernc}
\usepackage{DejavuSansMono}
有没有什么方法可以重新调整只是整个文档都使用等宽字体,而不管上下文如何?
示例文档
\documentclass[12pt]{scrartcl}
\usepackage[scale=0.8, a4paper]{geometry}
\usepackage[hidelinks]{hyperref}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{upquote} % fix rendering of quotes in verbatim context
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\newtcblisting{codeblock}{
arc=2pt,
listing only,
boxrule=0pt,
bottom=-8pt,
top=-5pt,
colback=black!5,
colframe=black!5,
listing options={
breaklines=true,
columns=fullflexible, % needed for copy-pasting
basicstyle=\ttfamily\color{black!70},
},
}
\usepackage[utf8x]{inputenc}
% \usepackage{lmodern}
\usepackage{fouriernc}
\usepackage{DejaVuSansMono}
\begin{document}
\section{Base situation}
\begin{minipage}{\linewidth}
Choosing the combination of \verb|fouriernc| the relative font size of inline \verb|\verb| test and inline \texttt{\string\texttt} text is too large. The issue is more pronounced when enabling \verb|DejavuSansMono|, but to a lesser degree present without. Likewise the contents of
\begin{verbatim}
verbatim
environment
\end{verbatim}
and the self-defined
\begin{codeblock}
codeblock
environment
\end{codeblock}
are too large.\footnote{It also should work in \texttt{\string\footnote} context.}
\end{minipage}
\section{Half-fixes}
The issue can be partly solved on a case-by-case basis, but this is undesirable. For instance, setting \verb|\verbatim@font|.
\makeatletter
\renewcommand\verbatim@font{{\scriptsize}\ttfamily}
\makeatother
For demonstration, here \verb|\verbatim@font| includes \verb|\scriptsize|, which does however not affect \texttt{\string\texttt}. This also affects the default
\begin{verbatim}
verbatim
environment
\end{verbatim}
but not the self-defined
\begin{codeblock}
codeblock
environment
\end{codeblock}
\begin{minipage}{\linewidth}
\footnote{In a footnote, the sizing would be anyway wrong, because {\csname verbatim@font\endcsname\string\scriptsize} is too large as font size correction for monospaced text here.}
\end{minipage}
As a consequence adjustments of the font size have to made in many different places.
\end{document}
答案1
恐怕您是从错误的前提出发的。比较一下标准的 Computer Modern 字体:
\documentclass{article}
\begin{document}
Abc \texttt{Abc} Abc
\end{document}
你可以看到等宽字体是更小比罗马字体大。但是,一些等宽字体的设计尺寸相当大。
另一方面,大多数字体包都允许scale
或scaled
选项,也不DejaVuSansMono
例外。
\documentclass{article}
\usepackage{fouriernc}
\usepackage[scaled=0.85]{DejaVuSansMono}
\begin{document}
Abc \texttt{Abc} Abc
\end{document}
在我看来并不是最匹配的,但这是个人喜好。
不相关:utf8x
选项inputenc
指向一个过时且不受支持的软件包。删除对的调用inputenc
(除非您有一个非常旧的 TeX 发行版)。