Rmarkdown PDF带有重音符号的山墙

时间:2018-07-29 15:34:31

标签: r pdf latex kable

我正在尝试创建一个包含一些文本的表,这些文本包含当前无法识别的某些字符。我包括了:

- \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)
    )

我得到的输出是

Screenshot of output

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

1 个答案:

答案 0 :(得分:1)

概述

在阅读@user2554330Producing pdf with knitr and Rmarkdown: accents in text show up but not in figures.的回答后,我使用了tikzDevice软件包的GitHub版本在.rmd输出中产生的图形中保留了重音符号。在使用data.frame()时,我还设置了static const struct { int limit; char *name; } rlimits[] = { { RLIMIT_NOFILE, "RLIMIT_NOFILE" }, { RLIMIT_NPROC, "RLIMIT_NPROC" }, // Etc. }; 以确保列名不是coerced to be syntactically valid names

SS of Output

.rmd代码

check.names = FALSE

会话信息

---
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://stackoverflow.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 )
```