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

查看:694
本文介绍了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

是否有4种字体(mainfont/sansfont/monofont/mathfont)用于描述Rmarkdown中的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标头的顶层定义这些选项.这是使用Liberif 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 ?   

第一个表使用Mono字体,即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天全站免登陆