5

\documentclass[11pt]{book}

This code shows default font size. I want to change font size all \ttfamily font in document (only for \ttfamily font). Other fonts not change.

How can I do? Thanks,

2
  • What do you want to change it to?
    – Werner
    Feb 5, 2014 at 19:44
  • \ttfamily show bigger than default font. Feb 5, 2014 at 19:48

4 Answers 4

4

You can update the definition of \ttfamily to include the font changes that you need. For example, below \ttfamily has been updated to always use \LARGE (say). Here is the default definition of \ttfamily from latex.ltx:

\DeclareRobustCommand\ttfamily
        {\not@math@alphabet\ttfamily\mathtt
         \fontfamily\ttdefault\selectfont}

Here is an updated version in the form of a minimal example:

enter image description here

\documentclass[11pt]{article}
\makeatletter
% Definition of \ttfamily from latex.ltx
\DeclareRobustCommand\ttfamily
        {\not@math@alphabet\ttfamily\mathtt
         \fontfamily\ttdefault\LARGE\selectfont}
\makeatother
\begin{document}
Some normal text.

{\ttfamily Some typewriter text.\par}

Some normal and \texttt{typewriter} text.
\end{document}

The above example also shows why this should not be done.

0
4

The most reliable way is to change the font definitions, applying a magnification factor. I'll do it for the T1 encoding, with a magnification factor of 1.1. Below the similar code for the OT1 encoding.

\documentclass[11pt]{book}
\usepackage[T1]{fontenc}

\makeatletter
\expandafter\let\csname T1/cmtt/m/n/10.95\endcsname\relax
\begingroup
\nfss@catcodes
\DeclareFontFamily{T1}{cmtt}{\hyphenchar \font\m@ne}
\DeclareFontShape{T1}{cmtt}{m}{n}{
        <-9>    s*[1.1] ectt0800
        <9-10>  s*[1.1] ectt0900
        <10-12> s*[1.1] ectt1000
        <12-17> s*[1.1] ectt1200
        <17->   s*[1.1] ectt1728
      }{}
\DeclareFontShape{T1}{cmtt}{m}{it}{
        <-9>    s*[1.1] ecit0800
        <9-10>  s*[1.1] ecit0900
        <10-12> s*[1.1] ecit1000
        <12-17> s*[1.1] ecit1200
        <17->   s*[1.1] ecit1728
      }{}
\DeclareFontShape{T1}{cmtt}{m}{sl}{
        <-9>    s*[1.1] ecst0800
        <9-10>  s*[1.1] ecst0900
        <10-12> s*[1.1] ecst1000
        <12-17> s*[1.1] ecst1200
        <17->   s*[1.1] ecst1728
      }{}
\DeclareFontShape{T1}{cmtt}{m}{sc}{
        <-9>    s*[1.1] ectc0800
        <9-10>  s*[1.1] ectc0900
        <10-12> s*[1.1] ectc1000
        <12-17> s*[1.1] ectc1200
        <17->   s*[1.1] ectc1728
      }{}
\DeclareFontShape{T1}{cmtt}{bx}{n}
       {<->sub  cmtt/m/n}{}
\DeclareFontShape{T1}{cmtt}{bx}{it}
       {<->sub  cmtt/m/it}{}
\DeclareFontShape{T1}{cmtt}{bx}{sl}
       {<->sub  cmtt/m/sl}{}
\DeclareFontShape{T1}{cmtt}{b}{n}
       {<->sub  cmtt/m/n}{}
\DeclareFontShape{T1}{cmtt}{b}{it}
       {<->sub  cmtt/m/it}{}
\DeclareFontShape{T1}{cmtt}{b}{sl}
       {<->sub  cmtt/m/sl}{}
\endgroup
\makeatother

\begin{document}
abc\texttt{def}ghi

\fontencoding{OT1}\selectfont
abc\texttt{def}ghi
\end{document}

The second line is just to show the difference with the original appearance. Apply the magnification factor you think best.

enter image description here

If you prefer sticking with OT1, then you should use the following code:

\makeatletter
\begingroup
\nfss@catcodes
\DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font\m@ne}
\DeclareFontShape{OT1}{cmtt}{m}{n}{
        <-9>    s*[1.1] cmtt8
        <9-10>  s*[1.1] cmtt9
        <10-12> s*[1.1] cmtt10
        <12->   s*[1.1] cmtt12
      }{}
\DeclareFontShape{OT1}{cmtt}{m}{it}{
        <->     s*[1.1] cmitt10
      }{}
\DeclareFontShape{OT1}{cmtt}{m}{sl}{
        <->     s*[1.1] cmsltt10
      }{}
\DeclareFontShape{OT1}{cmtt}{m}{sc}{
        <->     s*[1.1] cmtcsc10
      }{}
\DeclareFontShape{OT1}{cmtt}{m}{ui}
       {<->ssub*cmtt/m/it}{}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
       {<->ssub*cmtt/m/n}{}
\DeclareFontShape{OT1}{cmtt}{bx}{it}
       {<->ssub*cmtt/m/it}{}
\DeclareFontShape{OT1}{cmtt}{bx}{ui}
       {<->ssub*cmtt/m/it}{}
\endgroup
\makeatother
4

If you are willing to change the font, you can use a scalable font for ttfamily.

\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[scaled=0.8]{beramono}

\begin{document}
abc\texttt{def}ghi

\end{document}

enter image description here

1

A quick and dirty hack for inline typewriter font:

\newcommand{\texttx}[1]{{\small \texttt{#1}}}

1
  • Nice first answer, it could be improved by making it a small complete example starting with \documentclass{article} or similar and ending with \end{document}, even better would be with a picture so future readers can see the output, helps keep the site clean and is very helpful for future readers who might use your solution :)
    – JamesT
    Apr 7, 2023 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .