简体   繁体   English

为什么我的目录规范不能正常工作? 来自 Distill for R Markdown

[英]Why does my table of contents specifications not work properly? From Distill for R Markdown

Thank you for your help!感谢您的帮助!

I am having troubles with getting the table of contents (toc) into my Rmarkdown我在将目录 (toc) 放入我的 Rmarkdown 时遇到了麻烦

I have set up the document with the following YAML.. and according to https://bookdown.org/yihui/rmarkdown/html-document.html andhttps://rstudio.github.io/distill/basics.html#table-of-contents I should be able to get a nice toc.我已经使用以下 YAML.. 并根据https://bookdown.org/yihui/rmarkdown/html-document.htmlhttps://rstudio.github.io/distill/basics.html#table设置了文档-of-contents我应该能够得到一个不错的目录。 But it does not work for me.. Any idea?但这对我不起作用..有什么想法吗?

---
title: Evidence for Resilient Agriculture ERA
description: | 
  Using tidymodels to Explore Agroforestry Data 
date: "7/23/2021"
author:
  - first_name: "Kamau"
    last_name: "Lindhardt"
    url: https://www.linkedin.com/in/magnus-kamau-lindhardt/
    affiliation: World Agroforestry Centre, Nairobi
    affiliation_url: https://www.worldagroforestry.org
  - name: "Peter Steward"
bibliography: library.bib
csl: frontiers-in-ecology-and-the-environment.csl
output: distill::distill_article
toc: true
toc_float: 
collapsed: false
smooth_scroll: true
number_sections: true
toc_depth: 3
code_folding: true
---

With the content of my document like this:我的文档内容如下:

```{r setup, include=FALSE, code_folding=FALSE}
knitr::opts_chunk$set(
  echo = TRUE,
  warning = FALSE,
  message = FALSE,
  comment = "#",
  R.options = list(width = 60)
)
```


```{r ERA and ICRAF logo, fig.align='center', size=20, code_folding=TRUE}
library(cowplot)
ggdraw() + 
  draw_image("/Users/kamaulindhardt_1/Library/Mobile Documents/com~apple~CloudDocs/MSc Wageningen University /Internship ICRAF-ERA/R notes, codes and content/ERA_AGROFORESTRY/./IMAGES/ERA_logo_color.png", width = 0.5) + 
  draw_image("/Users/kamaulindhardt_1/Library/Mobile Documents/com~apple~CloudDocs/MSc Wageningen University /Internship ICRAF-ERA/R notes, codes and content/ERA_AGROFORESTRY/./IMAGES/ICRAF_logo.png", width = 0.5, x = 0.5)
```




# Libraries
```{r setup bookdown, include=TRUE}
library(bookdown)
library(tidyverse)
library(data.table)
library(kableExtra)
library(knitr)
library(here)
#library(cowplot)
```



# Section
## Subsection
### Subsubsection
#### Subsubsubsection

## Quarterly Results {.tabset}

some text

text 1

```{r include=FALSE, layout="l-screen-inset"}
rmarkdown::paged_table(mtcars)
```

```{r, dpi = 200, fig.align='center', fig.cap= 'first'}
plot(cars)
```


text 2

# Section

```{r, fig.align='center', fig.cap= 'second'}
plot(pressure)
```

text 3

# Section 4

## Subsection 4.1

```{r fig.align='center', tidy=TRUE, code_folding=TRUE}
library(ggplot2)
#qplot(x = Sepal.Length, y = Sepal.Width, data = iris, 
#      xlab="Sepal Length", ylab="Sepal Width", 
#      main="Sepal Length-Width", color=Species, shape=Species)

scatter <- ggplot(data=iris, aes(x = Sepal.Length, y = Sepal.Width)) 
scatter + geom_point(aes(color=Species, shape=Species)) +
  xlab("Sepal Length") +  ylab("Sepal Width") +
  ggtitle("Sepal Length-Width")
```

Instead, I get this with nothing inside.相反,我得到这个里面什么都没有。

knitted文档截图-toc中没有内容

..and there is no content in my table of content?? ..我的目录中没有内容??

I think is just a matter of formatting your YAML. When I pasted yours, I had the exact same result as you.我认为只是格式化您的 YAML 的问题。当我粘贴您的时,我得到的结果与您完全相同。 However, if I format it like this:但是,如果我这样格式化它:

title: Evidence for Resilient Agriculture ERA
description: | 
  Using tidymodels to Explore Agroforestry Data 
date: "7/23/2021"
author:
  - first_name: "Kamau"
    last_name: "Lindhardt"
    url: https://www.linkedin.com/in/magnus-kamau-lindhardt/
    affiliation: World Agroforestry Centre, Nairobi
    affiliation_url: https://www.worldagroforestry.org
  - name: "Peter Steward"
bibliography: library.bib
csl: frontiers-in-ecology-and-the-environment.csl
output: 
  distill::distill_article:
    toc: true
    number_sections: true
    toc_depth: 4
    code_folding: true
  toc_float: 
    collapsed: false
    smooth_scroll: true

I obtain this, with the TOC:我通过 TOC 获得了这个:

在此处输入图像描述

Obviously, I didn't add the images you have.显然,我没有添加您拥有的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM