Internationalization R knitr Figure caption label

风格不统一 提交于 2019-12-07 11:57:07

问题


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 = FALSE,  fig.cap = "RStudio IDE", fig.margin = T}
plot(pressure)
```

This generates:

However I want the caption label to read Figura: (portuguese) instead of Figure: . I added the variable lang: pt-br, which corrects for when I call it with \@ref(fig:rstudio), but does not fixes the figure label.

  • How to change the caption label in Rmarkdown?

回答1:


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.



来源:https://stackoverflow.com/questions/47173279/internationalization-r-knitr-figure-caption-label

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!