使代码输出的字体与Rmarkdown中文本的默认字体相同 [英] Making the output of code in the same font as that of the default font for the text in Rmarkdown
问题描述
这是一个代表:
---
date : 2018-May-27
output:
pdf_document:
latex_engine: xelatex
monofont: "Computer Modern"
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 some running text(in the Computer Modern font).
我只想要文档中的一种字体,即.文本的默认字体.为此,我添加了monofont行:"Computer Modern"(借此,我试图告诉软件以与文本相同的字体创建代码输出).当我尝试从上述Rmarkdown文件创建PDF时,出现以下错误.我有一个Ubuntu系统. 我怎样才能解决这个问题 ?
I want only ONE font in the document, ie. the default font for the text. To do this I have added the line monofont: "Computer Modern" (by this I am trying to tell the software to create the output of code in the same font as the text). I get the following error when I try to create a PDF from the above Rmarkdown file. I have a Ubuntu system. How can I fix this ?
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "Computer Modern" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................
这是在此处发布的原始查询的后续查询:[原始查询] Rmarkdown文档的字体
This is a follow up query to the original query posted here: [Original Query] Fonts for Rmarkdown document
推荐答案
实际上,它不是Computer Modern,而是默认使用的接近的Latin Latin Modern.因此,您可以尝试:
Actaully it is not Computer Modern but its close Relative Latin Modern that is used as default. So you could try:
---
date : 2018-May-26
output:
pdf_document:
latex_engine: xelatex
mainfont: Latin Modern Roman
monofont: Latin Modern Roman
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 ?
由于具有Ubuntu系统,因此可以使用fc-list
查看系统上安装的所有字体,这些字体可用于XeLaTeX.
Since you have an Ubuntu system, you can use fc-list
to see all the fonts installed on your system, that are available for XeLaTeX.
或者,如果您不想使用XeLaTeX,则可以使用
Alternatively, if you do not want to use XeLaTeX, you can use
output:
pdf_document
header-includes:
- \renewcommand*{\ttdefault}{lmr}
在标题中.
这篇关于使代码输出的字体与Rmarkdown中文本的默认字体相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!