Как изменить шрифт, используемый внутри чанков при вязании в виде tuffte_handout pdf? - PullRequest
1 голос
/ 22 мая 2019

Я работаю в книге, использую R и библиотеку Tufte.Я использую следующий YAML для каждой главы .Rmd:

---
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)
```

И следующий - YAML для файла индекса .Rmd:

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

# Preface {-}

Я пробовал разные варианты, напримердобавление sansfont и mainfont в YAML:

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 голосов
/ 23 мая 2019

Вы должны вывести заголовки YAML на правильный уровень:

  • monofont и др.являются заголовками верхнего уровня
  • highlight ниже выходного формата, а не ниже output

В следующем примере используется «Times New Roman» для блока кода и XeLaTeX по умолчаниюшрифт (латинский модерн) для основного текста.Вы можете изменить это с помощью 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

...