【已解决】如何设置、更换LaTeX Beamer的字体?以及调整正文所使用的字体(如从Times New Roman改变为Arial)、定义字体大小等操作

本文详细探讨了在LaTeX Beamer中如何选择和设置字体,包括serif和sans-serif字体类别,以及Overleaf支持的字体列表。作者分享了实际操作中的错误尝试和解决方案,帮助读者更好地理解和使用Overleaf中的字体配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 前言

创作开始时间:2021年12月12日21:21:07

感觉用LaTeX很简单,因为Overleaf上的模板太多了,但是要精通LaTeX,感觉要掌握的东西太多。本文主要对LaTeX Beamer中的字体设置进行研究。

备注:
第4节:“直接上代码!”包含实例代码。可以直接跳到这一节查看。

2. 关于字体

LaTeX的字体属性有四种:

  • family
  • shape
  • series
  • size

其中family属性主要可以归为三类:

  • serif 有衬线字体
  • sans serif (也叫做roman)。无衬线字体
  • monospaced 等宽字体

对于中文来说,宋体属于serif 字体,而黑体、幼圆、雅黑则属于sans serif 字体。
而英文,常用的 serif 字体为Times New Roman,常用的 sans serif 字体为Arial,Tahoma。

参考:

  • https://baike.baidu.com/item/serif/4199080?fr=aladdin
  • https://en.wikibooks.org/wiki/LaTeX/Fonts
  • LaTeX字体属性及其在中文Beamer中的使用 https://lttt.vanabel.cn/2018/06/04/latexzitishuxingjiqizaizhongwenbeamerzhongdeshiyong.html 这个还挺详细的。值得一看

3. Overleaf支持的字体

首先,所有的字体:

  • Fontname https://mirror-hk.koddos.net/CTAN/info/fontname/fontname.pdf 这个是官方文档

overleaf支持的字体没有那么多,具体可见官网(也挺多了):

  • Which OTF or TTF fonts are supported via fontspec? https://es.overleaf.com/learn/latex/Questions/Which_OTF_or_TTF_fonts_are_supported_via_fontspec%3F

4. 直接上代码!

\documentclass[xcolor=dvipsnames,9pt]{beamer}

% 使用theme
\usetheme{CambridgeUS} 
\useinnertheme{circles}

% 使用字体必备的包
\usepackage{fontspec}

# 定义字体
\newfontfamily\chalkd{DejaVu Sans}

# 设置beamer的字体
\setbeamerfont{normal text}{family=\chalkd,series=\mdseries}
\setbeamerfont{alerted text}{family=\chalkd,series=\bfseries}
\setbeamerfont{frametitle}{family=\chalkd,series=\bfseries}
% ,size={\fontsize{32}{36}}
\AtBeginDocument{\usebeamerfont{normal text}}

\title[Example]{Just an example!}
\author[xxx]{xxx}
\date{9th Dec, 2021}


\begin{document}
\begin{frame}
    \titlepage
\end{frame}

\section{Hello world}

\begin{frame}{Hello world now.}
    Hello world to every one.
\end{frame}
\end{document}

效果如下:
在这里插入图片描述

DejaVu Sans是一种无衬线字体。

换成:Alfios(一种有衬线字体,从https://es.overleaf.com/learn/latex/Questions/Which_OTF_or_TTF_fonts_are_supported_via_fontspec%3F oveleaf官网找的)之后,就变成了下面的样子:

在这里插入图片描述

4.1. 做过的错误尝试

  • 使用\setmainfont{font/Palatino.ttf}或者\setmainfont{palatino},貌似\setmainfont对Beamer没用。
  • 使用\setmainfont[ExternalLocation=font/]{POLYA.OTF}[Ligatures=TeX],没用
  • \defaultfontfeatures{Ligatures=TeX},没用
  • 使用overleaf官方提供的example:
\setromanfont{Times New Roman}
\setsansfont{Arial}
\setmonofont[Color={0019D4}]{Courier New}

也没用。

  • 还看了很多别的操作,试了下都没用。。。找到有用的还是费了不少时间的。

5. 小结

创作结束时间:

6. 参考文献

很多。

有用的:

  • latex - 如何使用\setbeamerfont 设置任何字体大小(例如 32pt)? https://www.coder.work/article/6681293
  • 参考别人的代码:
\usetheme{default}
\usepackage{mathpazo}
\usepackage{fontspec}
\setbeamertemplate{background canvas}{\includegraphics [width=\paperwidth]{blackboard_bk.pdf}}
\newfontfamily\chalkd{Chalkduster.ttf}
\newfontfamily\chalkb{Chalkboard.ttc}

\setbeamerfont*{normal text}{family = \chalkd}
\setbeamerfont{alerted text}{family = \chalkd}
\setbeamerfont{structure}{family = \chalkd}
\setbeamerfont{title}{family = \chalkd, size = \Huge}

\setbeamercolor{normal text}{fg=white}
\setbeamercolor{alerted text}{fg=yellow!80}
\setbeamercolor{structure}{fg=yellow!80}
\setbeamercolor{frametitle}{fg=white}
\setbeamercolor{title}{fg=white}
\setbeamertemplate{blocks}[shadow=false]
\setbeamercolor{block body}{fg=normal text.bg!90!black}
\setbeamercolor{block body example}{bg=normal text.bg!90!black}


\setsansfont{Chalkduster.ttf}
%\setmonofont{Chalkduster.ttf}

关于setmainfont :

  • How to \setmainfont when “randomfont.ttf” is in different folder? https://tex.stackexchange.com/questions/230186/how-to-setmainfont-when-randomfont-ttf-is-in-different-folder
  • \setmainfont vs \fontspec https://tex.stackexchange.com/questions/352804/setmainfont-vs-fontspec

设置字体:

  • Setting beamer text font https://tex.stackexchange.com/questions/489207/setting-beamer-text-font
  • Changing fonts in the body in beamer [duplicate] https://tex.stackexchange.com/questions/419920/changing-fonts-in-the-body-in-beamer
  • How to enforce a font series in beamer for normal/default text? https://tex.stackexchange.com/questions/320223/how-to-enforce-a-font-series-in-beamer-for-normal-default-text
  • Beamer Font: Change its Size, Family and style By Admin August 18, 2021 https://latex-beamer.com/tutorials/beamer-font/
  • Beamer template setbeamerfont bfseries https://tex.stackexchange.com/questions/236450/beamer-template-setbeamerfont-bfseries
  • What are all the possible first arguments to \setbeamerfont? tex.stackexchange.com/questions/183052/what-are-all-the-possible-first-arguments-to-setbeamerfont
  • Using a TrueType font in LaTeX with XeTeX https://gordonlesti.com/using-a-truetype-font-in-latex-with-xetex/
  • How to change fontspec’s default options https://tex.stackexchange.com/questions/431585/how-to-change-fontspec-s-default-options
  • latex字体设置 https://blog.csdn.net/wkd22775/article/details/51778920
  • How to modify Beamer theme? https://tex.stackexchange.com/questions/433595/how-to-modify-beamer-theme

xelatex:

  • Getting started with XeLaTeX https://robjhyndman.com/hyndsight/xelatex/
  • How to Use Different Fonts on Overleaf https://hongtaoh.com/en/2020/11/13/overleaf-latex-fonts/
  • Toying with Fonts in LaTeX huisaddison.com/blog/fonts-in-latex.html
  • XeLaTeX https://es.overleaf.com/learn/latex/XeLaTeX#The_basics:_Times_New_Roman
  • How to choose a specific weight from a font family using fontspec and XeLaTeX https://tex.stackexchange.com/questions/62603/how-to-choose-a-specific-weight-from-a-font-family-using-fontspec-and-xelatex
  • How to define a new font family on Beamer? https://tex.stackexchange.com/questions/177317/how-to-define-a-new-font-family-on-beamer#comment410588_177317

官方文档:

  • The fontspec package https://mirror-hk.koddos.net/CTAN/macros/unicodetex/latex/fontspec/fontspec.pdf
### 更改LaTeX数学公式默认字体 为了更改LaTeX中数学公式的默认字体,在不同的场景下有不同的方法。 对于一般的文档类(如`article`, `book`),如果希望将整个文档的数学字体更改为Times风格,可以在导言区加载特定宏包并配置相应选项。例如: ```tex \documentclass{article} \usepackage[T1]{fontenc} \usepackage{amsmath} \usepackage{mathptmx} % 使用 Times 字体作为正文和数学环境的主要字体[^1] % 或者使用 newtxmath 宏包获得更好的兼容性和效果 %\usepackage{newtxtext,newtxmath} \begin{document} ... \end{document} ``` 当涉及到XeLaTeX或LuaLaTeX编译器时,则可以通过`unicode-math`宏包来调整数学模式下的字体属性。此时可利用`\setmathfont`指令指定所需的字体文件路径或名称: ```tex \documentclass{article} \usepackage{amsmath} \usepackage{unicode-math} \setmainfont{Times New Roman} \setsansfont{Arial} \setmonofont{Courier New} \setmathfont{STIX Two Math}[Scale=MatchLowercase] % 设置匹配大小写的 STIX Two 数学字体 ``` 针对Beamer演示文稿模板,默认情况下其采用的是无衬线字体方案处理文本与公式部分;然而这并不总是理想的选择。为此,可通过引入额外的主题设定改变这一行为,使得数学表达式呈现更为正式美观的效果: ```tex \documentclass{beamer} \usetheme{default} \usefonttheme[onlymath]{serif} % 只影响数学环境内的字体为有衬线字体[^3] \begin{document} ... \end{document} ``` 通过以上几种方式之一即可实现对LaTeX数学公式默认字体样式的自定义设置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值