programing

R마크다운에서 목차를 추가하는 방법은 무엇입니까?

bestprogram 2023. 6. 6. 10:24

R마크다운에서 목차를 추가하는 방법은 무엇입니까?

저는 RStudio를 사용하여 마크다운 문서를 작성하고 있으며, 문서 상단에 TOC(Table of Contents)를 추가하여 사용자가 관련 섹션을 클릭하여 읽을 수 있도록 하고 싶습니다.rpub에 관련된 예시가 몇 개 있었는데 지금은 찾을 수 없는 것 같습니다.사용하지 않음을 유의하시기 바랍니다.pandoc그리고 꽤 처음입니다.Rmd&knitr사용하지 않고 TOC를 추가할 수 있는 방법이 있습니까?pandoc사용하는 경우pandoc그렇다면 어떤 기능이 관련이 있어야 합니까?

편집

다음은 작은 샘플 페이지입니다.

---
title: "Sample Document"
output:
  html_document:
    toc: true
    theme: united
---

Header 1
---------------
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
    
## Header 2
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
    
```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```
### Header 3
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

RStudio v0.98.864에서 실행하려고 시도했지만 작동하지 않았습니다! 슬프게도 0.98.501과 0.98.507에서는 작동하지 않았습니다.저는 0.98.501에 논문을 작성하고 있는데 RStudio를 업데이트한 후 일부 분석이 실패했습니다.그래서 다시 0.98.501로 되돌렸습니다.저는 이제 어떡하죠?저는 정말 TOCs를 원하지만 다른 분석 결과를 해치지는 않습니다.

구문은

---
title: "Sample Document"
output:
  html_document:
    toc: true
    theme: united
---

서류에.이것이 문서의 시작 부분에 있는지 확인합니다.또한 문서에 실제로 헤더가 있는지 확인하십시오. 그렇지 않으면 R은 목차에서 원하는 것을 말할 수 없습니다.

추가 옵션이 있는 구문:

---
title: "Planets"
author: "Manoj Kumar"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output: 
  html_document:
    toc: true # table of content true
    toc_depth: 3  # upto three depths of headings (specified by #, ## and ###)
    number_sections: true  ## if you want number sections at each table header
    theme: united  # many options for theme, this one is my favorite.
    highlight: tango  # specifies the syntax highlighting style
    css: my.css   # you can add your custom css, should be in same folder
---

사용 중인 경우pdf_document새 페이지에 목차를 추가하고 싶을 수 있습니다.toc: true허용하지 않습니다.목차는 문서 제목, 작성자 및 날짜 바로 뒤에 놓입니다. 왜냐하면 목차는 yaml로 되어 있기 때문입니다.

만약 당신이 그것을 새로운 페이지에 넣고 싶다면, 당신은 라텍스 언어를 사용해야 합니다.여기 제가 한 일이 있습니다.

---
title: \vspace{3.5in}"Title"
author: "Name"
date: "`r Sys.Date()`"
output:
   pdf_document:
      fig_caption: true
      number_sections: true
---

\newpage # adds new page after title
\tableofcontents # adds table of contents
\listoffigures
\listoftables
\newpage

그래서, yaml (--- 사이의 청크) 다음으로, 저는 다음을 사용하여 새로운 페이지를 추가했습니다.\newpage다음을 사용하여 목차를 사용합니다.\tableofcontents을 사용한 숫자 목록\listoffigures표 목록\listoftables그리고 다른 모든 것보다 새로운 페이지.

메모,\vspace{3in}제목에서 yaml(그림 등)을 인쇄하기 전에 위에서 3인치의 수직 공간을 추가합니다.

여기서 더 읽기: https://www.sharelatex.com/learn/Table_of_contents

언급URL : https://stackoverflow.com/questions/23957278/how-to-add-table-of-contents-in-rmarkdown