如何使用 Bookdown 更改单个文档中的标题标签名称?
How to change caption label names in a single document with Bookdown?
我创建了一个 single document,其中 Bookdown-package 为 R-Markdown,它允许 html- 和 pdf-output。我想将标题标签 Figure
、Table
和 Table of Contents
更改为另一种语言。这是一个最小的例子:
---
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
---
# Erstes Kapitel
Abbildung \@ref(fig:pressure) ist Deutsch.
```{r pressure, echo=FALSE, out.width = "80%", fig.pos='h', fig.cap="Deutsche Bildunterschrift"}
plot(pressure)
```
Bookdown 使用英文单词 'Figure' 作为图形标题前缀。当编织到 pdf_document2 时,Bookdown 使用英文单词 'Contents' 作为目录。如何将它们更改为 'Abbildung' 和 'Inhalt'?
我已阅读 Bookdown 手册中的 section 4.5 Internationalization。作者建议编辑一个配置文件_bookdown.yml
,其中可以更改标签名称。但是,我找不到这样的配置文件,我的单Bookdown-document好像是self-contained。此外,第 4.5 节中的示例并未说明如何更改 toc 的术语。
我发现 和 \renewcommand
。这适用于使用 output:pdf_document2
时的图形和表格,但不适用于 output:html_document2
。作为附带问题,\renewcommand{\contentsname}{Inhalt}
不会将 'Contents' 更改为 pdf-output 中的 'Inhalt'。所以 \renewcommand
不是理想的解决方法。
其实我更想使用 Bookdown 手册上面第 4.5 节中描述的原始解决方案。我写一个Bookdown-document的时候哪里找这个配置文件_bookdown.yml
?我可以在该文件的哪个位置更改 toc 的术语?如果我必须首先创建这个配置文件,我应该怎么做以及如何 link 它到我的单身 Rmd-document?
如果我将您的示例代码保存为 deutsch.rmd
然后渲染它,我可以重现您描述的内容。
如果然后我在与 deutsch.rmd
相同的目录 中创建一个名为 _bookdown.yml
的文件,其中包含
language:
label:
fig: "Abbildung "
和re-render,单词"Figure"在HTML输出中被替换为"Abbildung"。
如果我创建一个名为 preamble.tex
的文件,其中包含
\usepackage[german]{babel}
并调整 deutsch.rmd
的 YAML header 以读取
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
includes:
in_header: preamble.tex
PDF 输出也切换为德语。
编辑:我只是found out myself,这个解决方案似乎等同于使用以下YAML header:
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
lang: de
请注意,上述 PDF 输出解决方案使用 "Inhaltsverzeichnis" 而不是 "Inhalt"。
如果您真的想根据自己的喜好简单地更改图形标签和 table 内容 header,而不依赖 babel
做正确的事情,您可以使用以下 preamble.tex
改为:
\renewcommand{\figurename}{Abbildung}
\renewcommand{\contentsname}{Inhalt}
我创建了一个 single document,其中 Bookdown-package 为 R-Markdown,它允许 html- 和 pdf-output。我想将标题标签 Figure
、Table
和 Table of Contents
更改为另一种语言。这是一个最小的例子:
---
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
---
# Erstes Kapitel
Abbildung \@ref(fig:pressure) ist Deutsch.
```{r pressure, echo=FALSE, out.width = "80%", fig.pos='h', fig.cap="Deutsche Bildunterschrift"}
plot(pressure)
```
Bookdown 使用英文单词 'Figure' 作为图形标题前缀。当编织到 pdf_document2 时,Bookdown 使用英文单词 'Contents' 作为目录。如何将它们更改为 'Abbildung' 和 'Inhalt'?
我已阅读 Bookdown 手册中的 section 4.5 Internationalization。作者建议编辑一个配置文件_bookdown.yml
,其中可以更改标签名称。但是,我找不到这样的配置文件,我的单Bookdown-document好像是self-contained。此外,第 4.5 节中的示例并未说明如何更改 toc 的术语。
我发现 \renewcommand
。这适用于使用 output:pdf_document2
时的图形和表格,但不适用于 output:html_document2
。作为附带问题,\renewcommand{\contentsname}{Inhalt}
不会将 'Contents' 更改为 pdf-output 中的 'Inhalt'。所以 \renewcommand
不是理想的解决方法。
其实我更想使用 Bookdown 手册上面第 4.5 节中描述的原始解决方案。我写一个Bookdown-document的时候哪里找这个配置文件_bookdown.yml
?我可以在该文件的哪个位置更改 toc 的术语?如果我必须首先创建这个配置文件,我应该怎么做以及如何 link 它到我的单身 Rmd-document?
如果我将您的示例代码保存为 deutsch.rmd
然后渲染它,我可以重现您描述的内容。
如果然后我在与 deutsch.rmd
相同的目录 中创建一个名为 _bookdown.yml
的文件,其中包含
language:
label:
fig: "Abbildung "
和re-render,单词"Figure"在HTML输出中被替换为"Abbildung"。
如果我创建一个名为 preamble.tex
的文件,其中包含
\usepackage[german]{babel}
并调整 deutsch.rmd
的 YAML header 以读取
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
includes:
in_header: preamble.tex
PDF 输出也切换为德语。
编辑:我只是found out myself,这个解决方案似乎等同于使用以下YAML header:
title: Dokument auf Deutsch
output:
bookdown::html_document2:
toc: yes
bookdown::pdf_document2:
toc: yes
lang: de
请注意,上述 PDF 输出解决方案使用 "Inhaltsverzeichnis" 而不是 "Inhalt"。
如果您真的想根据自己的喜好简单地更改图形标签和 table 内容 header,而不依赖 babel
做正确的事情,您可以使用以下 preamble.tex
改为:
\renewcommand{\figurename}{Abbildung}
\renewcommand{\contentsname}{Inhalt}