0

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

enter image description here

\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} 
3
  • 2
    \usepackage[scaled=0.5]{DejaVuSansMono} (adapt the value naturally ...) Commented Feb 2, 2022 at 13:52
  • note UTF-8 is the default so better to omit \usepackage[utf8x]{inputenc} or use \usepackage[utf8]{inputenc} or just use \usepackage[utf8x]{inputenc} if you need compatibility with old documents using the utf8x configuration. Commented Feb 2, 2022 at 14:01
  • 2
    latex does not by deafult make the monospace font large, it chooses both fonts at exactly the same nominal design size. If you choose two font families for tt and rm or rm and sf or whatever, then it is quite common that you need to scale one or the other to mak ethem blend together better, Commented Feb 2, 2022 at 14:03

1 Answer 1

5

I'm afraid you're starting from a false premise. Compare the standard Computer Modern fonts:

\documentclass{article} \begin{document} Abc \texttt{Abc} Abc \end{document} 

enter image description here

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 or scaled option and DejaVuSansMono is no exception.

\documentclass{article} \usepackage{fouriernc} \usepackage[scaled=0.85]{DejaVuSansMono} \begin{document} Abc \texttt{Abc} Abc \end{document} 

enter image description here

Not the best match to my eye, but it's personal preference.

Unrelated: the utf8x option to inputenc refers to an obsolete and unsupported package. Remove the call to inputenc (unless you have a very old TeX distribution).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.