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