【发布时间】:2019-08-12 07:04:03
【问题描述】:
使用 huxtable,为不同的单元格/行输出不同字体的 html 是一件轻而易举的事。没有那么多的pdf。 这并不是一个真正的新问题,而是一个特定版本的 RMarkdown - different font types in table using kable? 和 Change font of Kable in Rmarkdown pdf
我已使用https://stackoverflow.com/a/54735453/4927395 给出的答案从 rmarkdown(在我的 Windows 电脑上)创建下图中的输出。请注意,“环境”代码将更改表格(整个表格)的字体,但块之后的文本是为表格指定的字体。 建议解决这个问题? 此外,我无法让浮动示例在我的计算机上工作,这就是它被注释掉的原因。 我喜欢 huxtable,但还没有看到为表格选择的字体(与主字体不同)在网络上工作的示例。如果绝对必要,可以探索其他表包。
---
title: "Reprex selecting font for kable table output to pdf"
output:
pdf_document:
latex_engine: xelatex
header-includes:
\usepackage{fontspec}
\setmainfont[Path=C:/windows/fonts/]{SHOWG.TTF}
\newfontfamily\arialfont[Path=c:/windows/fonts/]{ARIAL}
\newenvironment{ctable}{\arialfont }{}
\newenvironment{capctable}[1][t]{\begin{table}[#1]\centering\arialfont}{\end{table}}
---
here is some text
```{r}
library(knitr)
library(kableExtra)
#This works, though leaves the selected font active for text after the chunk
kable(head(mtcars), booktabs=TRUE, align = "c") %>%
kable_styling(table.envir="ctable", font_size=12) %>%
row_spec(0, bold = T, color = "white", background = "gray")
#This next bit doesn't work
#kable(head(mtcars), booktabs=TRUE, align = "c",
# caption = "This table floats", table.envir = "capctable") %>%
# kable_styling(font_size=12) %>%
# row_spec(0, bold = T, color = "white", background = "gray")
```
here is some more text
【问题讨论】:
-
huxtable 的开发版现在允许您控制 PDF 版本中的字体。 github.com/hughjonesd/huxtable/issues/…
标签: fonts r-markdown kable kableextra