【问题标题】:Internationalization R knitr Figure caption label国际化 R knitr 图标题标签
【发布时间】:2017-11-08 06:50:02
【问题描述】:

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

```{r rstudio, echo = FALSE,  fig.cap = "RStudio IDE", fig.margin = T}
plot(pressure)
```

这会生成:

但是我希望标题标签读取 Figura: (portuguese) 而不是 Figure: 。我添加了变量lang: pt-br,当我用\@ref(fig:rstudio) 调用它时它会更正,但不会修复图形标签。

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

【问题讨论】:

    标签: r knitr r-markdown


    【解决方案1】:

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

    正如this answer 解释的那样,“图”和“内容”等名称存储在\figurename\contentsname 等宏中。要更改它们,您必须在序言中使用 \renewcommand 更改相应宏的定义:

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

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

    • \abstractname [仅限articlereport]:摘要
    • \appendixname:附录
    • \bibname [仅限 book, report]:参考书目
    • \chaptername[仅限bookreport]:章节
    • \contentsname:内容
    • \figurename:图
    • \indexname:索引
    • \listfigurename:人物列表
    • \listtablename:表列表
    • \partname:部分
    • \refname [仅限article]:参考文献
    • \tablename:表

    这是您的场景的 MWE:

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

    替代方法

    神奇的包 bookdown 扩展了 RMarkdown 和 knitr 的基础知识。正如here 所解释的,该软件包允许您设置内部化的一件事。

    【讨论】:

    • 这很好用!你知道如何摆脱标签和数字之间的空间吗? \renewcommand{\figurename}{YOUR LABEL} 将产生“YOUR LABEL 1”,而我想要“YOUR LABEL1”。
    猜你喜欢
    • 1970-01-01
    • 2013-01-23
    • 1970-01-01
    • 2018-05-12
    • 2010-09-10
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多