这是一个最小的工作示例。
---
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文档的默认字体是什么?如何更改它们?
在研究这个问题时,我遇到了这个页面:
[Pandoc变量] [1] http://pandoc.org/MANUAL.html#variables-for-latex
在Rmarkdown中描述4类输出有4种字体(mainfont / sansfont / monofont / mathfont)是否正确?它们的默认值是什么?如何更改它们?
答案 0 :(得分:4)
创建PDF文件时使用LaTeX。 LaTeX中使用的默认字体是Computer Modern。有多种方法可以更改LaTeX使用的字体,但如果不知道LaTeX,则所需的名称通常不直观。更简单的解决方案是将mainfont
等与xelatex
或lualatex
一起用作引擎。您可以使用平台的标准字体名称在yml
标题的顶层定义这些选项。这里使用Liberation Serif作为主要字体的示例文档:
---
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输出。第二个表再次使用主字体。有关详细信息,请参阅documentation。