Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201977

Including a graphic in PDF with xelatex

$
0
0

I'm trying to include an image in a kableExtra table, but it will only be included if I remove the xelatex and setmainfont code from my markdown. Does anyone have a solution for this? I have tried with a jpg and png but have the same issue.

The code below compiles but the images are blank.

---
title: "markdownTest"
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}
- \usepackage{fontspec}
- \setmainfont{Calibri}
output: 
  pdf_document:
    latex_engine: xelatex
geometry: margin=0.5in
---

```{r message=FALSE, warning=FALSE}
library(knitr)
df <- data.frame(
  stock = c('Apple','Amazon','Microsoft','Tesla'),
  value = c(300,200,150,250),
  difference = c(50,-10,20,-15)
)
df$trend <- ifelse(df$difference >0,
                   '![](Check.jpg)',
                   '![](Flag.jpg)'
                  )

kable(df, escape = F)
```

The below code, without xelatex, setmainfont, and \usepackage{fontspec}, works as expected.

---
title: "markdownTest"
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}
output: 
  pdf_document
geometry: margin=0.5in
---

```{r message=FALSE, warning=FALSE}
library(knitr)
df <- data.frame(
  stock = c('Apple','Amazon','Microsoft','Tesla'),
  value = c(300,200,150,250),
  difference = c(50,-10,20,-15)
)
df$trend <- ifelse(df$difference >0,
                   '![](Check.jpg)',
                   '![](Flag.jpg)'
                  )

kable(df, escape = F)
```

I'm trying to upload my jpg to this post but am getting an error. The flag is just a red warning exclamation, and the check is a green check. Please let me know if you need any other information, thank you.


Viewing all articles
Browse latest Browse all 201977

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>