代码之家  ›  专栏  ›  技术社区  ›  Dylan_Gomes

R markdown目录未出现在HTML中

  •  1
  • Dylan_Gomes  · 技术社区  · 11 月前

    使用Rmd的模板,我添加 toc: true 对于yaml来说,文件很复杂,但找不到toc。相反,文本“true”出现在文档中。

    ---
    title: "Untitled"
    author: "Author Name"
    date: "2024-08-06"
    output: html_document
    toc: true
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ## R Markdown
    
    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>.
    
    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 cars}
    summary(cars)
    ```
    
    ## Including Plots
    
    You can also embed plots, for example:
    
    ```{r pressure, echo=FALSE}
    plot(pressure)
    ```
    
    Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
    

    enter image description here

    稍微改变一下的yaml没有帮助:

    ---
    title: "Untitled"
    author: "Author Name"
    date: "2024-08-06"
    output: 
      html_document:
      toc: true
    ---
    

    文本“true”消失了,但没有TOC。思想?

    > sessionInfo()
    R version 4.4.0 (2024-04-24 ucrt)
    Platform: x86_64-w64-mingw32/x64
    Running under: Windows 10 x64 (build 19045)
    
    Matrix products: default
    
    
    locale:
    [1] LC_COLLATE=English_United States.utf8  LC_CTYPE=C                             LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
    [5] LC_TIME=English_United States.utf8    
    
    time zone: America/Los_Angeles
    tzcode source: internal
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     
    
    loaded via a namespace (and not attached):
     [1] jsonlite_1.8.8     dplyr_1.1.4        compiler_4.4.0     promises_1.3.0     tidyselect_1.2.1   Rcpp_1.0.12        stringr_1.5.1      later_1.3.2        jquerylib_0.1.4   
    [10] yaml_2.3.8         fastmap_1.2.0      mime_0.12          R6_2.5.1           plyr_1.8.9         shinyjs_2.1.0      generics_0.1.3     knitr_1.47         tibble_3.2.1      
    [19] shiny_1.8.1.1      bslib_0.7.0        pillar_1.9.0       rlang_1.1.3        utf8_1.2.4         cachem_1.1.0       stringi_1.8.4      xfun_0.44          httpuv_1.6.15     
    [28] sass_0.4.9         cli_3.6.2          magrittr_2.0.3     shinyWidgets_0.8.6 digest_0.6.35      rstudioapi_0.16.0  xtable_1.8-4       lifecycle_1.0.4    vctrs_0.6.5       
    [37] evaluate_0.23      glue_1.7.0         rsconnect_1.3.1    fansi_1.0.6        reshape2_1.4.4     rmarkdown_2.27     tools_4.4.0        pkgconfig_2.0.3    htmltools_0.5.8.1 
    
    1 回复  |  直到 11 月前
        1
  •  1
  •   stefan    11 月前

    你必须注意正确的压痕。这个 toc 是一个选项 html_document 因此,在第二种方法中,你必须缩进 toc: true 通过另外两个空格:

    ---
    title: "Untitled"
    author: "Author Name"
    date: "2024-08-06"
    output: 
      html_document:
        toc: true
    ---
    

    完成此操作后,您将获得:

    enter image description here