编织成tuffte_handout pdf时如何更改大块内部使用的字体?

时间:2019-05-22 00:26:13

标签: r latex r-markdown tufte

我正在使用R和Tufte库编写一本书。 我为每个.Rmd章使用以下YAML:

---
title: "Chapter 2: A First Linear Program"
header-includes:
 \usepackage{longtable}
 \usepackage{caption}
output:
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
  highlight: monochrome
  tufte::tufte_html: default
  tufte::tufte_book:
    citation_package: natbib
    latex_engine: xelatex
---

\pagestyle{headings}


```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```

以下是索引.Rmd文件的YAML:

---
title: "Operations Research Using R<br />"
author: "Timothy R. Anderson"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: ["Master4Bookdowns.bib"]
---

# Preface {-}

我尝试了其他选项,例如在YAML中添加sansfont和mainfont:

output:
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
  highlight: monochrome
  sansfont: Calibri Light
  mainfont: Calibri Light

但是它并没有更改块内的字体,仅更改了外面的文本。


下面是一个更简单的示例文档,显示了我根据注释中的建议尝试更改monofont的情况:

---
title: "Chapter 2: A First Linear Program"
header-includes:
\usepackage{longtable}
 \usepackage{caption}
output:
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
    toc: TRUE
    number_sections: true
  highlight: monochrome
  monofont: Times New Roman
  tufte::tufte_html: default
  tufte::tufte_book:
    citation_package: natbib
    latex_engine: xelatex
---

\pagestyle{headings}


```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```

This is an example, where we can see that text in the book is affected by the use of command
monofont: Times New Roman in the YAML. However, we can see that next chunk, the oucome when generating the tuffte_handout pdf is using a different font and also using multiple colors (no only black as in the main body).


```{r base_case_no_pipes_step_4}

model0d <- c("example", 6 + 2 <= 2000) 
#fabrication
model0e <- c("example", 8 + 6 <= 2000)  
#assembly    
```

1 个答案:

答案 0 :(得分:0)

您必须将YAML标头设置为正确的级别:

  • monofont等。是顶级标题
  • highlight在输出格式下方,而不是在output
  • 下方

以下示例将“ Times New Roman”用作代码块,并将XeLaTeX的默认字体(Latin Modern)用作主要文本。您可以使用mainfont进行更改。此外,没有语法高亮显示:

---
title: "Chapter 2: A First Linear Program"
header-includes:
- \usepackage{longtable}
- \usepackage{caption}
monofont: Times New Roman
output:
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
    toc: TRUE
    number_sections: true
    highlight: monochrome
  tufte::tufte_html: default
  tufte::tufte_book:
    citation_package: natbib
    latex_engine: xelatex
---

\pagestyle{headings}


```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```

This is an example, where we can see that text in the book is affected by the use of command
monofont: Times New Roman in the YAML. However, we can see that next chunk, the oucome when generating the tuffte_handout pdf is using a different font and also using multiple colors (no only black as in the main body).


```{r base_case_no_pipes_step_4}

model0d <- c("example", 6 + 2 <= 2000) 
#fabrication
model0e <- c("example", 8 + 6 <= 2000)  
#assembly

```

结果:

enter image description here