Rmarkdown 文档的字体 [英] Fonts for Rmarkdown document

查看:15
本文介绍了Rmarkdown 文档的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个最小的工作示例.

Here is a minimal working example.

---
date : 2018-May-26
output:
    pdf_document
title: "Testing Rmarkdown"
---

```{r,comment = NA}

Gender <- gl(2,1000,labels = c("Men","Women"))
SmokerM <- sample(c("Y","N"),1000,replace = T , prob = c(.3,.7))
SmokerW <- sample(c("Y","N"),1000,replace = T , prob = c(.5,.5))
Smoker <- c(SmokerM,SmokerW)

mydata  <- data.frame(Gender,Smoker)
table(mydata$Gender,mydata$Smoker)

```

This is a text in the body of the document.What font is this ? What is
font for the output of table ? How can we change these 2 fonts ? What 
other categories of items are there in an Rmarkdown which have different
fonts ?       

我的查询如下:Rmarkdown 文档的默认字体是什么,如何更改它们?

My query is the following: What are the default fonts for an Rmarkdown document and how can I change them ?

在研究这个时,我遇到了这个页面:

While researching this I came across this page :

[Pandoc 变量][1]http://pandoc.org/MANUAL.html#variables-for-latex

[Pandoc variables][1]http://pandoc.org/MANUAL.html#variables-for-latex

在 Rmarkdown 中有 4 种字体(mainfont/sansfont/monofont/mathfont)用于描述 4 类输出是否正确?它们的默认值是什么,我该如何更改它们?

Is it correct that there are 4 fonts (mainfont/sansfont/monofont/mathfont) for describing 4 categories of output in Rmarkdown ? What are their default values and how can I change them ?

推荐答案

创建 PDF 文件时使用 LaTeX.LaTeX 中使用的默认字体是 Computer Modern.有多种方法可以更改在 LaTeX 中使用的字体,但如果不了解 LaTeX,则所需的名称通常不直观.一个更简单的解决方案是使用 mainfont 等与 xelatexlualatex 作为引擎.您可以使用平台的标准字体名称在 yml 标头的顶层定义这些选项.这里使用 Liberation Serif 作为主要字体的示例文档:

LaTeX is used when you create a PDF file. And the default font used in LaTeX is Computer Modern. There are various ways to change the fonts used n LaTeX, but the required names are often not intuitive if one does not know LaTeX. An easier solution is to use mainfont etc. together with xelatex or lualatex as engine. You can define these options at the top level in the yml header using standard font names for your platform. Here your example document using Liberation Serif as main font:

---
date : 2018-May-26
output:
    pdf_document:
        latex_engine: xelatex
mainfont: LiberationSerif
sansfont: LiberationSans
monofont: LiberationMono
title: "Testing Rmarkdown"
---

```{r,comment = NA}

Gender <- gl(2,1000,labels = c("Men","Women"))
SmokerM <- sample(c("Y","N"),1000,replace = T , prob = c(.3,.7))
SmokerW <- sample(c("Y","N"),1000,replace = T , prob = c(.5,.5))
Smoker <- c(SmokerM,SmokerW)

mydata  <- data.frame(Gender,Smoker)
table(mydata$Gender,mydata$Smoker)
knitr::kable(table(mydata$Gender,mydata$Smoker))
```

This is a text in the body of the document.What font is this ? What is
font for the output of table ? How can we change these 2 fonts ? What 
other categories of items are there in an Rmarkdown which have different
fonts ?   

第一个表使用单声道字体,即 Liberation Mono,因为它是正常的 R 输出.第二个表再次使用主字体.有关详细信息,请参阅 文档.

The first table uses the mono font, i.e. Liberation Mono, since it is normal R output. The second table uses the main font again. See the documentation for more details.

这篇关于Rmarkdown 文档的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆