Making the output of code in the same font as that of the default font for the text in Rmarkdown

前端 未结 1 1142
花落未央
花落未央 2020-12-22 05:35

Here is a reprex :

---
date : 2018-May-27
output:
    pdf_document:
        latex_engine: xelatex
monofont: \"Computer Modern\"
title: \"Testing Rmarkdown\"
         


        
相关标签:
1条回答
  • 2020-12-22 05:52

    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 ?   
    

    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.

    Alternatively, if you do not want to use XeLaTeX, you can use

    output:
        pdf_document
    header-includes:
        - \renewcommand*{\ttdefault}{lmr}
    

    in the header.

    0 讨论(0)
提交回复
热议问题