How to suppress automatic table name and number in an .Rmd file using xtable or knitr::kable?

后端 未结 2 857
甜味超标
甜味超标 2020-12-14 22:35

I\'d like to name my tables from R scripts without the automatic Table 1:... prefix when using xtable() or knitr::kable() in an .Rmd f

相关标签:
2条回答
  • 2020-12-14 23:13

    It turns out that I needed to add the following in the YAML section:

    header-includes:
        - \usepackage{caption}
    

    AND the following somewhere before the code chunk:

    \captionsetup[table]{labelformat=empty}
    

    Now it works:

    ---
    title: "Suppress automatic table name and number"
    output: pdf_document
    header-includes:
        - \usepackage{caption}
    ---
    
    \captionsetup[table]{labelformat=empty}
    
    ```{r myirischunk, results = 'asis', tab.cap = NULL, echo = TRUE}
    print(knitr::kable(head(iris), caption = "Table 21.a - My very own table name"))
    ```
    

    This has also been described here:

    Get rid of captions using texreg in markdown

    And yes, I'm a bit embarrased that I didn't find that answer straight away.

    Anyway, thanks to daroczig for pointing me in the tex direction instead of trying to solve the problem using chunk options or something like that.

    0 讨论(0)
  • 2020-12-14 23:21

    In case you also want figures the same way, modify the example by vestland to

    ---
    title: "Suppress automatic table name and number"
    output: pdf_document
    header-includes:
        - \usepackage[labelformat=empty]{caption}
    ---
    

    and skip the \captionsetup{}.

    0 讨论(0)
提交回复
热议问题