ChatGPT解决这个技术问题 Extra ChatGPT

How do you change the document font in LaTeX?

How do you change the font for the whole document to sans-serif (or anything else)?


H
Huliax

I found the solution thanks to the link in Vincent's answer.

 \renewcommand{\familydefault}{\sfdefault}

This changes the default font family to sans-serif.


The font used is Helvetica as explained in stat.berkeley.edu/~paciorek/computingTips/…
@nalply On my system it is Computer Modern Sans, most definitely not Helvetica (which is not available for free by the way). The source you cite is wrong.
What if you want a specific font, not a random font from the family?
Other options apart from sfdefault are rmdefault (serif) and ttdefault (monospaced), according to this.
S
Simon C.

For a different approach, I would suggest using the XeTeX or LuaTex system. They allow you to access system fonts (TrueType, OpenType, etc) and set font features. In a typical LaTeX document, you just need to include this in your headers:

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setmainfont{Times}
\setmonofont{Lucida Sans Typewriter}

It's the fontspec package that allows for \setmainfont and \setmonofont. The ability to choose a multitude of font features is beyond my expertise, but I would suggest looking up some examples and seeing if this would suit your needs.

Just don't forget to replace your favorite latex compiler by the appropriate one (xelatex or lualatex).


d
dmckee --- ex-moderator kitten

As second says, most of the "design" decisions made for TeX documents are backed up by well researched usability studies, so changing them should be undertaken with care. It is, however, relatively common to replace Computer Modern with Times (also a serif face).

Try \usepackage{times}.


What exactly does "well researched usability studies" mean? Do you just mean well thought out? I can't imagine there exist peer reviewed studies of the specific LaTeX defaults in academic journals.
@Praxeolitic You would ask me that after I moved away from the office that kept copies of both the TeXbook and Lamport's LaTeX: A Document Preparation System lying around. I think it is in Lamport, but I can't swear to it.
"Most". The default font is too hard to read, I prefer something lighter with less complexity in letter glyphs
Have to say, I think the default Computer Modern font looks hideous. (With apologies to Donald Knuth.) Your mileage may vary.
I find serif font quite a bad choice for reading. in fact, there are probably the same studies showing the opposite regarding fonts. The serifs aren't very well prepared for reading. IMHO.
C
Casey Jones

This article might be helpful with changing fonts.

From the article:

The commands to change font attributes are illustrated by the following example:

  \fontencoding{T1}
  \fontfamily{garamond}
  \fontseries{m}
  \fontshape{it}
  \fontsize{12}{15}
  \selectfont

This series of commands set the current font to medium weight italic garamond 12pt type with 15pt leading in the T1 encoding scheme, and the \selectfont command causes LaTeX to look in its mapping scheme for a metric corresponding to these attributes.