带有重音符号的 Rmarkdown pdf kable

Rmarkdown pdf kable with accents

我正在尝试创建一个 table 文本,其中包含一些当前无法识别的字符。我已经包括:

- \usepackage[utf8]{inputenc}

和我的代码:

kable(t(tabela.nIncendiosUrbanos),
      caption="\label{tab:nIncendiosUrbanos} Adaptado de Anuário de Ocorrências de Protecção Civil - ANPC.",
      "latex", align="c", booktabs=TRUE, escape=FALSE) %>%
  kable_styling(latex_options = "striped", full_width = F)

其中,

tabela.nIncendiosUrbanos <- data.frame(
      'Edifício de habitação'=c(7000, 7300, 7200, 7200, 7439),
      "Estacionamento"=c(65, 60, 80, 60, 55),
      "Edifício de Serviço"=c(270, 250, 167, 180, 235),
      "Equipamento Escolar"=c(120, 130, 130, 150, 161),
      "Equipamento Hospitalar e Lar de Idosos"=c(80, 95, 65, 100, 88),
      "Edifício de Espetáculos, Lazer e Culto Religioso"=c(70, 80, 65, 75, 69),
      "Hotelaria e Similares"=c(450, 490, 470, 430, 448),
      "Edifício Comercial"=c(430, 350, 300, 290, 290),
      "Edifício Cultural"=c(20, 25, 20, 30, 23),
      "Indústria, Oficina e Armazém"=c(1000, 1230, 1100, 1100, 1237)
    )

我得到的输出是

有人可以帮我解决问题吗?

概览

看完@user2554330's answer to Producing pdf with knitr and Rmarkdown: accents in text show up but not in figures., I used the GitHub version of the tikzDevice package to keep accent marks in figures produced from the .rmd output. I also set check.names = FALSE when using data.frame() to ensure the column names were not coerced to be syntactically valid names

.rmd代码

---
title: 'Keeping Accent Marks in PDF Output'
author: 'Cowboy Bebop'
date: '`r format(Sys.Date(), "%B %Y")`'
output: pdf_document
---


```{r global options, echo = FALSE, message = FALSE}
# install this particular package from GitHub
# using the 'devtools' package
# install.packages( pkgs = 'devtools' )
devtools::install_github( repo = "daqana/tikzDevice" )

# load necessary packages
library( kableExtra )
library( knitr )
library( magrittr )
library( tikzDevice )

# requesting xelatex instead of the default LaTeX engine does seem to work
# thank you to SO for this answer 
# https://whosebug.com/a/46220592/7954106
options( tikzDefaultEngine = "xetex" )

# load neccesary data
tabela.nIncendiosUrbanos <- data.frame(
      'Edifício de habitação'        = c(7000, 7300, 7200, 7200, 7439),
      "Estacionamento"               = c(65, 60, 80, 60, 55),
      "Edifício de Serviço"          = c(270, 250, 167, 180, 235),
      "Equipamento Escolar"          = c(120, 130, 130, 150, 161),
      "Equipamento Hospitalar e Lar de Idosos"           = c(80, 95, 65, 100, 88),
      "Edifício de Espetáculos, Lazer e Culto Religioso" = c(70, 80, 65, 75, 69),
      "Hotelaria e Similares"        = c(450, 490, 470, 430, 448),
      "Edifício Comercial"           = c(430, 350, 300, 290, 290),
      "Edifício Cultural"            = c(20, 25, 20, 30, 23),
      "Indústria, Oficina e Armazém" = c(1000, 1230, 1100, 1100, 1237),
      # setting check.names equal to FALSE
      # to avoid coercing the column names
      # to be synatactically valid
      # for more info, see ?make.names
      check.names = FALSE )
```

# Produce a table using `knitr::kable()`

```{r Produce table}
kable( x = t( x = tabela.nIncendiosUrbanos)
       , caption = "\label{tab:nIncendiosUrbanos} Adaptado de Anuário de Ocorrências de Protecção Civil - ANPC."
       , format = "latex"
       , align = "c"
       , booktabs = TRUE
       , escape = FALSE ) %>%
  kable_styling( latex_options = "striped"
                 , full_width = FALSE )
```

Session 信息

R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] devtools_1.13.6  tikzDevice_0.12  magrittr_1.5     knitr_1.20      
[5] kableExtra_0.9.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18      rstudioapi_0.7    xml2_1.2.0        hms_0.4.2        
 [5] munsell_0.5.0     rvest_0.3.2       viridisLite_0.3.0 colorspace_1.3-2 
 [9] R6_2.2.2          rlang_0.2.1       filehash_2.4-1    plyr_1.8.4       
[13] stringr_1.3.1     httr_1.3.1        tools_3.5.1       grid_3.5.1       
[17] withr_2.1.2       htmltools_0.3.6   yaml_2.1.19       digest_0.6.15    
[21] rprojroot_1.3-2   tibble_1.4.2      crayon_1.3.4      readr_1.1.1      
[25] memoise_1.1.0     evaluate_0.11     rmarkdown_1.10    stringi_1.2.4    
[29] compiler_3.5.1    pillar_1.3.0      scales_0.5.0      backports_1.1.2  
[33] pkgconfig_2.0.1