LaTeX learning portal (6) (font)

LaTeX font description

Font family

Presented in the text content in addition to fonts as well as font shape and size of the font. Usually we are used to set the font. For example thesis often requires font New TIme Romance font, font here can be considered a font family. If you need to set LaTeX text fonts usually refers to the set font.
Here Insert Picture Description

Font shape

For articles that appear in English characters usually need to be italicized, chapter titles are usually bold. Here's italics, bold font refers to the paper text. The following are common font:
Here Insert Picture Description
on the table switching command means that shaped everything after all if I want to perform. For example, I want everything after the paper is bold, you can set up \bfseriesand then all of the following contents will appear in bold. But in practice we often need to modify a noun or a certain period of use bold \textbf{文字}to amend the text as text .

Note : Not all glyphs available in all shapes above, when the time is not specified font will usually L a T e X LaTeX compile time based alert and is output.

font size

LaTeX \LaTeX font size is typically specified in the instruction. The following table is a common font size and settings.
Here Insert Picture Description

Customize any font

% 下面的设置将使用指定的字体族设置文章中对应需要的部分。例如英文正文部分将全部采用`Times New Roman`字体
\setmainfont{Times New Roman}     
\setsansfont{Dotum}               
\setmonofont{Droid Sans Fallback} 

Chinese font set

\setCJKsansfont{Adobe 楷体 Std}
\setCJKmonofont{LiHei Pro}
% 设置中文主体部分的字体为Adobe宋体,但是对于字形斜体和粗体不使用Adobe宋体的默认字体而是采用方正姚体和方正舒体
\setCJKmainfont[BoldFont={方正舒体}, ItalicFont={方正姚体}, BoldItalicFont={方正等线}]{Adobe 宋体 Std}

If we want to customize a piece of text fonts you do not want to affect the overall text, you can:

% 设置hwhp为华文琥珀字体
\setCJKfamilyfont{hwhp}{华文琥珀}
% 使用\hwhp命令设置字体
\newcommand{\hwhp}{\CJKfamily{hwhp}}

Then you can use {\hwhp 你想设置的文字}to set the font style you want.
All tex file as follows:

\usepackage[T1]{fontenc}
\usepackage{inputenc}
\usepackage{float}
\usepackage{array}
\setmainfont{Times New Roman}
\setsansfont{Dotum}
\setmonofont{Droid Sans Fallback}

% \setCJKmainfont[BoldFont={LiHei Pro Bold}, ItalicFont={LiHei Pro Italic}, BoldItalicFont={LiHer Pro Bold Italic}]{LiHei Pro}
\setCJKsansfont{Adobe 楷体 Std}
\setCJKmonofont{LiHei Pro}
\setCJKmainfont[BoldFont={方正舒体}, ItalicFont={方正姚体}, BoldItalicFont={方正等线}]{Adobe 宋体 Std}
\setCJKfamilyfont{hwhp}{华文琥珀}
\newcommand{\hwhp}{\CJKfamily{hwhp}}
\newfontfamily\semib[Path=fonts/]{SourceSansPro-SemiboldIt.otf}
\begin{document}

下面的文章内容关于的是$\LaTeXe$文章中的字体,你可以自定义字体。setmainfont主要定义英文字体。这里的默认字体为Times New Roman。
中文字体主要为LiHei Pro。下面的字体的不同形状展示,\textbf{粗体},\textit{斜体}。下面的内容主要是展示粗体部分文字:
\textbf{这里写一个故事:从前有座山,山里有座庙,庙里有个老和尚和小和尚讲故事。}看到了吧,即使主题字体设置的是Adobe宋体但是粗体的时候是按照方正舒体设置的。里面的BoldFont之类的字体均可以改成你想用的字体。下面斜体版本的故事:
\textit{从前有座山,山里有座庙,庙里有个老和尚和小和尚讲故事。}实际上每个字体都会有响应的粗体、斜体、倾斜之类的字体。在Word里面我们可以直接设置字形。但是在LaTeX中如果你不加设置,粗体的字体将是你指定的字体的粗体。例如上面的例子中如果不设置,主体字体的粗体将显示LiHei Pro的粗体。

如果你想指定任意字体,你可以自定义CJKfamily。例如:
{\hwhp 从前有座山,山里有座庙,庙里有个老和尚和小和尚讲故事。}
自定义英文部分字体:{\semib hello world!}

\end{document}

效果如下:
Here Insert Picture Description
需要注意的是:如果你没有安装上面的字体,latex编译通常会提示找不到字体。而且在Ubuntu下上面的字体应该均不能找到。因此你需要在你的Ubuntu上安装上述字体(将windows的fonts目录直接拷贝到/usr/share/fonts使用fc-cache -vf安装即可。)实际上上面的字体还用到了苹果常用的LiHei Pro字体。如果你不愿意折腾,将上面的字体替换成你自己有的字体即可。

如何找到系统上安装的字体并进行设置?

我的计算机环境为Ubuntu18.0.4,你可以搜索优化找到优化->字体.界面如下:
Here Insert Picture Description
需要特别注意的是:LaTeX指定的字体是字体族,没有形状。例如如果我想使用华文云彩,你可以看到华文云彩实际上后面还有RegularItalic之类的形状,但是在tex文件中不能加上后面的字形。否则将提示找不到字体。

如何指定字体文件?

有时候我们的论文会在不同的电脑之间来回编辑,不同电脑的字体不一定完全包含有tex文件需要的字体,这时候为每一台电脑安装指定的字体将是一个非常繁杂的工作。你可以将你需要的字体放在你的论文目录下,然后通过字体文件使用字体。这样还能在版本管理工具git上方便使用。
你如在你的论文中存在fonts目录用来存放字体SourceSansPro-SemiboldIt.otf,你可以使用

\newfontfamily\semib[Path=fonts/]{SourceSansPro-SemiboldIt.otf}

LaTeX将使用\semib调用新的字体,实现改变英文部分的文字字体。

文件链接可以从这里找到ex6
文章参考如下:

Published 65 original articles · won praise 26 · Views 100,000 +

Guess you like

Origin blog.csdn.net/bleedingfight/article/details/89297974