我正在尝试在pdf的kable列中包含png。我使用rmarkdown :: render编织pdf。我也在使用tinytex和xelatex。图像在html和word doc中都能正常工作,但我不知道为什么它在pdf中不起作用。
图像在电缆外面很好呈现。
这是我的代码:
---
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"
```{r message=FALSE, warning=FALSE, results='asis'}
library(knitr)
library(rmarkdown)
library(kableExtra)
up <- knitr::include_graphics("up-arrow.png", dpi = 100)
down <- knitr::include_graphics("C:/Users/datimmer/Desktop/Notes/down-arrow.png")
up
down
cat("![](",'C:/Users/datimmer/Desktop/Notes/up-arrow.png)',")")
'![](C:/Users/datimmer/Desktop/Notes/up-arrow.png)'
paste0('![test](C:/Users/datimmer/Desktop/Notes/up-arrow.png)')
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,
sprintf('![](%s)', 'C:/Users/datimmer/Desktop/Notes/up-arrow.png'),
knitr::include_graphics("C:/Users/datimmer/Desktop/Notes/down-arrow.png")
)
knitr::kable(df, 'latex')
这是我的pdf与此代码相似的样子,因为您可以看到png在电缆外面很好地呈现。
这是我的会话信息:
> session_info()
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1, RStudio 1.2.1335
Locale:
LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
LC_MONETARY=English_United States.1252 LC_NUMERIC=C
LC_TIME=English_United States.1252
Package version:
askpass_1.1 assertthat_0.2.1 backports_1.1.4
base64enc_0.1.3 bayesDccGarch_2.1 BH_1.69.0-1
brew_1.0.6 broom_0.5.2 callr_3.2.0
cellranger_1.1.0 cli_1.1.0 clipr_0.6.0
clisymbols_1.2.0 coda_0.19.2 codetools_0.2-16
colorspace_1.4-1 commonmark_1.7 compiler_3.6.0
covr_3.3.1 crayon_1.3.4 crosstalk_1.0.0
curl_3.3 DBI_1.0.0 dbplyr_1.4.0
desc_1.2.0 devtools_2.2.1 digest_0.6.19
dplyr_0.8.1 DT_0.6.2 ellipsis_0.3.0
evaluate_0.14 fansi_0.4.0 forcats_0.4.0
foreach_1.4.4 fs_1.3.1
generics_0.0.2 ggplot2_3.1.1
gh_1.0.1 git2r_0.25.2 glue_1.3.1
graphics_3.6.0 grDevices_3.6.0 grid_3.6.0
gtable_0.3.0 haven_2.1.0 highr_0.8
hms_0.4.2 htmltools_0.3.6 htmlwidgets_1.3
httpuv_1.5.1 httr_1.4.0 ini_0.3.1
iterators_1.0.10 jsonlite_1.6 kableExtra_1.1.0.9000
knitr_1.25 labeling_0.3 later_0.8.0
lattice_0.20-38 lazyeval_0.2.2 lubridate_1.7.4
magrittr_1.5 markdown_0.9 MASS_7.3.51.4
Matrix_1.2.17 memoise_1.1.0 methods_3.6.0
mgcv_1.8.28 mime_0.7 modelr_0.1.4
munsell_0.5.0 nlme_3.1-139 numDeriv_2016.8.1
openssl_1.3 PerformanceAnalytics_1.5.2 pillar_1.4.0
pkgbuild_1.0.3 pkgconfig_2.0.2 pkgload_1.0.2
plogr_0.2.0 plyr_1.8.4 png_0.1-7
pracma_2.2.5 praise_1.0.0 prettyunits_1.0.2
processx_3.3.1 progress_1.2.2 promises_1.0.1
ps_1.3.0 purrr_0.3.2 quadprog_1.5-7
R6_2.4.0 rcmdcheck_1.3.3 RColorBrewer_1.1.2
Rcpp_1.0.1 RcppArmadillo_0.9.400.3.0 readr_1.3.1
readxl_1.3.1 rematch_1.0.1 remotes_2.1.0
reprex_0.3.0 reshape2_1.4.3 rex_1.1.2
rlang_0.3.4 rmarkdown_1.12 RODBC_1.3-15
roxygen2_6.1.1 RPostgreSQL_0.6-2 rprojroot_1.3-2
rstudioapi_0.10 rversions_2.0.0 rvest_0.3.4
scales_1.0.0 selectr_0.4.1 sessioninfo_1.1.1
shiny_1.3.2 sourcetools_0.1.7 splines_3.6.0
stats_3.6.0 stringi_1.4.3 stringr_1.4.0
sys_3.2 testthat_2.1.1 tibble_2.1.1
tidyr_0.8.3 tidyselect_0.2.5 tidyverse_1.2.1
tinytex_0.17 tools_3.6.0 usethis_1.5.0
utf8_1.1.4 utils_3.6.0 vctrs_0.1.0
viridisLite_0.3.0 webshot_0.5.1.9001 whisker_0.3.2
withr_2.1.2 xfun_0.11 XML_3.98-1.19
xml2_1.2.0 xopen_1.0.0 xtable_1.8.4
xts_0.11-2 yaml_2.2.0 zeallot_0.1.0
zoo_1.8-5