使用xelatex在PDF中包含图形

时间:2019-11-25 17:04:14

标签: r latex r-markdown kable xelatex

我试图在kableExtra表中包括一个图像,但是只有当我从markdown中删除xelatex和setmainfont代码时,才会包括该图像。有人对此有解决方案吗?我曾尝试使用jpg和png,但存在相同的问题。

下面的代码可以编译,但是图像为空白。

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

下面的代码没有xelatex,setmainfont和\ usepackage {fontspec},可以正常工作。

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

我正在尝试将我的jpg上传到该帖子,但出现错误。该标志只是红色的警告感叹号,而支票是绿色的支票。请让我知道是否需要其他信息,谢谢。

这是.log唯一引用jpg的时间

    File: """Check".jpg Graphic file (type bmp)
<"""Check".jpg>
File: """Flag".jpg Graphic file (type bmp)
<"""Flag".jpg>
File: """Check".jpg Graphic file (type bmp)
<"""Check".jpg>
File: """Flag".jpg Graphic file (type bmp)
<"""Flag".jpg>
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 175.
[1

]

这里是对xelatex的全部引用

Package: mathspec 2016/12/22 v0.2b LaTeX Package (Mathematics font selection fo
r XeLaTeX)
Package: fontspec 2019/03/15 v2.7c Font selection for XeLaTeX and LuaLaTeX

(c:/Users/AppData/Roaming/TinyTeX/texmf-dist/tex/latex/fontspec/fontsp
ec-xetex.sty
Package: fontspec-xetex 2019/03/15 v2.7c Font selection for XeLaTeX and LuaLaTe
X
\l__fontspec_script_int=\count191
\l__fontspec_language_int=\count192
\l__fontspec_strnum_int=\count193
\l__fontspec_tmp_int=\count194
\l__fontspec_tmpa_int=\count195
\l__fontspec_tmpb_int=\count196
\l__fontspec_tmpc_int=\count197
\l__fontspec_em_int=\count198
\l__fontspec_emdef_int=\count199
\l__fontspec_strong_int=\count266
\l__fontspec_strongdef_int=\count267
\l__fontspec_tmpa_dim=\dimen144
\l__fontspec_tmpb_dim=\dimen145
\l__fontspec_tmpc_dim=\dimen146

我看不到上载整个.log的选项,因此我只是尝试包括相关部分。

0 个答案:

没有答案