Rmarkdown Beamer presentation, option clash clash for xcolor

梦想的初衷 提交于 2019-12-10 18:44:14

问题


I am trying to build a beamer presentation using rmarkdown. In my presentation I want to include tables using the kable, and kableExtra packages. I am having issues with this because one of the LaTex packages that kableExtra requires is already loaded by the beamer presentation with different options. This is the error message that I receive.

! LaTeX Error: Option clash for package xcolor.

I have been searching for a fix for this but have not had any luck. I have found solutions on the LaTex pages, here and here, but I do not know LaTex and I have not figured out how to apply these solutions in the rmarkdown arena. I have tried looking at the Latex templates in rmarkdown, but I do not understand it well enough to try and implement these solutions.

Any thoughts or solutions would be much appreciated. Here is just a quick sample of the .Rmd that gives the error.

---
title: "Untitled"
author: "Author"
date: "April 28, 2018"
output: 
  beamer_presentation:
    keep_tex: true
header-includes:
- \usepackage[table]{xcolor}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:6]
```


## Slide with R Output

```{r cars, echo = TRUE}
kable(dt, format = "latex") 
```

## Slide with Plot

```{r pressure}
plot(pressure)
```

回答1:


The linked answer on the TeX stackexchange suggests adding table to the class options for the document e.g. \documentclass[a4paper,table]{article}. In order to do this in RMarkdown, you can use a classoption: line in your YAML header:

---
title: "Untitled"
author: "Author"
date: "April 28, 2018"
classoption: table
output: 
  beamer_presentation:
    keep_tex: true
---


来源:https://stackoverflow.com/questions/50094698/rmarkdown-beamer-presentation-option-clash-clash-for-xcolor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!