By default, LaTeX makes monospaced text rather large relative to the default serif ("roman") text. This is especially pronounced when choosing custom fonts, e.g.
\usepackage{fouriernc}
\usepackage{DejavuSansMono}
Is there some way to rescale just the monospaced fonts across the document, regardless of the context?
Example document
\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}
Best Answer
I'm afraid you're starting from a false premise. Compare the standard Computer Modern fonts:
You can see that the monospaced font is smaller than the Roman counterpart. However, several monospaced fonts have a rather large design size.
On the other hand, most font packages allow for a
scale
orscaled
option andDejaVuSansMono
is no exception.Not the best match to my eye, but it's personal preference.
Unrelated: the
utf8x
option toinputenc
refers to an obsolete and unsupported package. Remove the call toinputenc
(unless you have a very old TeX distribution).