Internationalization R knitr Figure caption label

后端 未结 1 1017
故里飘歌
故里飘歌 2021-02-10 04:31

I want to generate a Latex document with knitr, but it does not allow me to change the label for the figure into my language. The code:

```{r rstudio, echo = FAL         


        
1条回答
  •  感情败类
    2021-02-10 05:16

    You can actually include LaTeX code directly within the Rmd file to alter the settings.

    As this answer explains, names like "Figure" and "Contents" are stored in macros like \figurename and \contentsname. To change them, you have to change the definition of the respective macros using \renewcommand within your preamble:

    \renewcommand{\figurename}{Fig.}
    \renewcommand{\contentsname}{Table of Contents}
    

    Here's a list of the "name macros" (and their default meaning) defined by the LaTeX standard classes article, book, and report:

    • \abstractname [only article, report]: Abstract
    • \appendixname: Appendix
    • \bibname [only book, report]: Bibliography
    • \chaptername [only book, report]: Chapter
    • \contentsname: Contents
    • \figurename: Figure
    • \indexname: Index
    • \listfigurename: List of Figures
    • \listtablename: List of Tables
    • \partname: Part
    • \refname [only article]: References
    • \tablename: Table

    Here is a MWE for your scenario:

    ---
    output:
      pdf_document: default
    ---
    \renewcommand{\figurename}{YOUR LABEL}
    \renewcommand{\tablename}{TABLE LABEL}
    
    ```{r Table, echo =FALSE}
    knitr::kable(iris[1:5,], caption = "A table")
    ```
    
    ```{r pressure, echo=FALSE, fig.cap="Test Caption"}
    plot(pressure)
    ```
    

    Alternative Approach

    The fantastic package bookdown expands a lot on the basics of RMarkdown and knitr. One thing the package allows you to set internalisation, as explained here.

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