在markdown中更改文档标题和作者名称的字体

7
我正在使用rmarkdown来生成pdf文档,可以通过在RStudio中或使用R中的render()函数进行转换。请问有人能给我一些指针,以更改文档标题和作者名称所使用的字体的大小、颜色等方面的内容吗?我已经通过编辑文档中的前置内容(front matter)实现了许多像更改整体字体等方面的进展,但在这个问题上我完全迷失了。请注意,我不太懂LaTeX......感谢任何帮助!
2个回答

3

迟做总比不做好。

如果要更改默认的rmarkdown布局中的个别部分,则需要使用一些LaTeX。

首先,这里有一个可重现的示例:

---
title: "Lord of the Rings"
author: "J. R. R. Tolkien"
header-includes:
  - \usepackage{xcolor}
  - \usepackage{fetamont}
  - \newcommand*\eiadfamily{\fontencoding{OT1}\fontfamily{eiad}\selectfont}
  - \newcommand{\mytitle}{\eiadfamily}
  - \newcommand{\myauthor}{\ffmfamily \textcolor{blue}}
  - \pretitle{\vspace{\droptitle}\centering\huge\eiadfamily}
  - \preauthor{\centering\large\myauthor}
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


## Chapter 1

在这种方法中,我们不需要包含自定义的TeX模板。我们利用rmarkdown使用LaTeX包titling创建文档标题的事实。文档可以在此处找到。
通过该包的命令\pretitle\preauthor,我们可以重新定义标题的样式。rmarkdown使用的默认值为(请参见Github上的代码)。
\pretitle{\vspace{\droptitle}\centering\huge}
\preauthor{\centering\large\emph}

现在来看代码。我们做了什么:

我们导入了两个包,xcolorfetamont。第一个包用于使用颜色,而后一个包则是包含我们想要使用的字体的包。

接下来的三行代码定义了三个新命令。第一个命令(\eiadfamily)用于将字体族设置为eiad。 另外两个命令(\myauthor\mytitle)则只是结合了字体和颜色的设置。

最后,我们重新定义了\preauthor\pretitle

\pretitle{\vspace{\droptitle}\centering\huge\eiadfamily}
\preauthor{\centering\large\myauthor}

请注意,我从\preauthor中删除了\emph,因为 ffm 字体家族的斜体版本不可用。
以下是结果: enter image description here 可以在 http://www.tug.dk/FontCatalogue/ 找到可用字体的概述。

非常好的答案。值得指出的是,如果字体已经安装在系统中,您可以简单地使用“- \newcommand*\eiadfamily{\setmainfont{eiad}}”。 - DaveRGP

1
只需要添加一个CSS代码块就解决了我的问题:
{css echo=FALSE}
.author {color: black; font-family: cursive }
.title {color: black; font-family: cursive }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接