【发布时间】:2020-11-28 11:02:53
【问题描述】:
我正在尝试在 bookdown 项目中 kable 呈现的表格中使用复选标记 unicode 字符 (\u2713)。一个 MWE 由以下 2 个文件(index.Rmd、preamble.tex)组成,是生成的最小 bookdown 项目的一部分。
index.Rmd
---
title: "A Minimal Book Example"
subtitle: "subtitle"
lang: fr
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
mainfont: Arial
mathfont: Arial
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
subparagraph: yes
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
---
```{r setup, include=FALSE}
# Set locale to french for month and day names (calendar plots)
Sys.setlocale(locale = 'French')
# Load all needed libraries
if(!require('pacman'))install.packages('pacman')
pacman::p_load(kableExtra)
```
(ref:O3) O~3~
# Prerequisites
✓
```{r stations-polluants, echo=FALSE}
stations_polluants_table <- data.frame(
stations = c("41B001", "41B004", "41B011", "41MEU1", "41N043", "41R001", "41R002", "41R012", "41WOL1", "Total / polluant"),
O3 = c("", rep("✓", 5), "", rep("\u2713", 2), "7")
)
kable(stations_polluants_table, col.names = c("Station", "(ref:O3)"), booktabs = T, align = "c", caption = "Caption text") %>%
row_spec(0, bold = T) %>%
row_spec(10, bold = T) %>%
collapse_rows(columns = 1, latex_hline = "major", valign = "top")
```
```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```
preamble.tex
\usepackage{booktabs}
\newfontfamily{\unicodefont}{Arial Unicode MS}
\usepackage{newunicodechar}
\newunicodechar{✓}{{\unicodefont{✓}}}
通过使用rmarkdown::render_site(output_format = 'bookdown::pdf_book', encoding = 'UTF-8') 编译PDF,可以注意到✓ 在文本中正确呈现,而在生成的表格中它被替换为。我还尝试在表格中使用\u2713,但没有取得更多成功。
我做错了什么?请注意,即使首选输出是 PDF,我也想编译为 gitbook(因此 Rmd 文件需要保持独立于输出格式)。
非常感谢。
【问题讨论】:
标签: pdf unicode bookdown kable kableextra