Changing *Chapter X* name in bookdown PDF

情到浓时终转凉″ 提交于 2019-12-02 07:43:56

问题


Instead of Chapter X when creating a PDF from bookdown, I would like it to be "Módulo X" (in Spanish).

So I would like to know how to change chapter name using bookdown.

My YAML is:

--- 
title: "TITLE"
author: "Mario Modesto-Mata"
date: "`r Sys.Date()`"
output: pdf_document
description: This is a minimal example of using the bookdown package to write a book.
  The output format for this example is bookdown::gitbook.
documentclass: book
link-citations: yes
bibliography: book.bib
site: bookdown::bookdown_site
language:
  label:
    chapter_name: "Módulo"
---

I tried with the last three line codes, with no success. Any idea?


回答1:


From the bookdown documentation we can learn two things:

  • There is no language.label.chapter_name but language.ui.chapter_name.
  • This setting is meant for HTML output. For PDF output one should configure LaTeX.

Configuring LaTeX is quite simple. You only need to add lang: es to your header. However, this will use "Capítulo" instead of "Módulo". One can adjust this by redefining the LaTeX command \chaptername. BTW, at the moment you are not using bookdown but the standard pdf_docuemnt from rmarkdown. If you wont to use bookdown features, you should use bookdown::pdf_book or bookdown::pdf_document2.

Putting everything together:

--- 
title: "TITLE"
author: "Mario Modesto-Mata"
date: "`r Sys.Date()`"
output: bookdown::pdf_book
description: This is a minimal example of using the bookdown package to write a book.
  The output format for this example is bookdown::gitbook.
documentclass: book
lang: es
link-citations: yes
bibliography: book.bib
site: bookdown::bookdown_site
header-includes:
  - \AtBeginDocument{\renewcommand{\chaptername}{Módulo}}
---

Result:

Note that header-includes is nice for simple stuff in single file documents like this minimal example. In most cases one is better off including a tex into the header via output.<your-format>.includes.in_header, c.f. Include TeX header in R package for RMarkdown documents.



来源:https://stackoverflow.com/questions/54676107/changing-chapter-x-name-in-bookdown-pdf

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