保留pdf书签文本时如何获取标题无衬线?

时间:2018-08-31 15:02:19

标签: r latex r-markdown knitr pandoc

在rmarkdown中,我希望使用无衬线字体的标题。我可以使用\textsf{} latex命令来实现,但是稍后在PDF中没有显示书签文本。我已经尝试过## \textsf[Heading 1]{Heading 1},但结果出错。

有人知道如何同时获得两者吗?

MWE:

---
output: pdf_document
---

## \textsf{Heading 1}

Lorem ipsum dolor sit amet, sit id rebum choro euripidis, nam ei ullum tamquam scaevola, est veniam consulatu et. Duo ex utamur atomorum. His ad dicat pericula, solet appetere vel cu. 

## \textsf{Heading 2}

Lorem ipsum dolor sit amet, sit id rebum choro euripidis, nam ei ullum tamquam scaevola, est veniam consulatu et. Duo ex utamur atomorum. His ad dicat pericula, solet appetere vel cu. 

输出:

enter image description here

想要:

带有文本“标题1”,“标题2”的书签(左)。

1 个答案:

答案 0 :(得分:4)

请勿将逻辑标记(“这是标题”)与物理标记(“这是无衬线”)混合使用。而是将物理标记附加到逻辑标记,例如使用titlesec包:

---
output: pdf_document
subparagraph: yes
header-includes:
  - \usepackage[sf,bf]{titlesec}
---

## Heading 1

Lorem ipsum dolor sit amet, sit id rebum choro euripidis, nam ei ullum tamquam scaevola, est veniam consulatu et. Duo ex utamur atomorum. His ad dicat pericula, solet appetere vel cu. 

## Heading 2

Lorem ipsum dolor sit amet, sit id rebum choro euripidis, nam ei ullum tamquam scaevola, est veniam consulatu et. Duo ex utamur atomorum. His ad dicat pericula, solet appetere vel cu.