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.
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
: TableHere 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)
```
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With