0

I thought the task would be so easy I will be able find an answer in a second. As it turned out, I can't make my verb| | look smaller without changing the "global" settings (which isn't what I want). I want to set a scale factor or a font size a bit smaller for the default's (I guess it's CM) typewriter font. How can I do it?

\documentclass[10pt]{article}
% expect something like this \usepackage[scale=0.9]{monospacefont}
\begin{document}
Hello \verb|world|
\end{document}
  • Do you just want to change the font size for \verb(*) and verbatim(*), and keep the font size unchanged for \ttfamily and \texttt? If so, you can redefine \verbatim@font. For example, to append \small, use \renewcommand*\verbatim@font{\normalfont\ttfamily\small}. – muzimuzhi Z Jun 15 '20 at 13:43
  • Yes, you got me right. However, your solution doesn't work. It breaks the verbatim layout and prints @ at the beginning. Also, it does not affect the \verb. I think something is misspelled. I think you are close to the right answer... – Timur Fayzrakhmanov Jun 17 '20 at 13:49

1 Answers1

0

Finally, I found the answer.

\makeatletter
\def\verbatim@font{\small\ttfamily}
\makeatother

It doesn't matter where you put it (before or after \begin{document}). It changes the font size only for verb and verbatim environment. \small is where you need to put the size that fits your needs.

Originally posted here.