国际化R Knitr图形标题标签 [英] Internationalization R knitr Figure caption label

查看:84
本文介绍了国际化R Knitr图形标题标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用knitr生成Latex文档,但不允许我将图形的标签更改为我的语言.代码:

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)
```

这将生成:

不过,我希望标题标签显示为Figura :(葡萄牙语),而不是Figure:.我添加了变量lang: pt-br,该变量可以在用\@ref(fig:rstudio)调用时进行更正,但不能修复图形标签.

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.

  • 如何在Rmarkdown中更改标题标签?

推荐答案

实际上,您可以直接在Rmd文件中包含LaTeX代码以更改设置.

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

正如此答案所述,诸如"Figure"和"Contents"之类的名称存储在诸如\contentsname.要更改它们,您必须使用前导中的\renewcommand来更改相应宏的定义:

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}

这是LaTeX标准类articlebookreport定义的名称宏"(及其默认含义)的列表:

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

  • \abstractname [仅articlereport]:摘要
  • \appendixname:附录
  • \bibname [仅bookreport]:参考书目
  • \chaptername [仅bookreport]:章节
  • \contentsname:内容
  • \figurename:图
  • \indexname:索引
  • \listfigurename:图形列表
  • \listtablename:表列表
  • \partname:部分
  • \refname [仅article]:参考
  • \tablename:表格
  • \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

这是适合您的情况的MWE:

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)
```

替代方法

出色的软件包预订在RMarkdown和knitr的基础上进行了很多扩展.该软件包允许您设置内部化的一件事,如此处所述.

这篇关于国际化R Knitr图形标题标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆