我已使用此stackoverflow question中的代码将图像包含在表中。但是,使用'adjustimage'height参数增加行高似乎对图像高度没有影响。我希望在表格中包含的图像比标记必须比文字高度高时要详细得多。
我正在处理.Rmd文档,需要pdf输出。
---
title: "Image in table using xtable and adjustbox"
output: pdf_document
header-includes:
- \usepackage{adjustbox}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(xtable)
# flags from: https://www.iconfinder.com/search/?q=orange+flag&price=free
```
```{r image function, include = FALSE}
get_picture_code <- function(path, height, col = NULL){
paste0("\\adjustimage{height = ", height, ", valign = M, margin* = 1ex}{", path, "}")
}
```
```{r image in xtable adjustbox method, results='asis'}
dat <- data.frame(country = c("Belgium", "Germany", "Holland", "Ireland"),
var1 = 1:4,
var2 = 11:14)
mypath <- paste0("images/", dat$country, ".png")
dat$flag <- get_picture_code(path = mypath, height = "3cm")
print(xtable(dat,
align = c("l","l","l","l","c"),
caption = "Example with flags"),
sanitize.text.function = identity,
comment = FALSE)
```
图像尽管高度=“ 3cm”,但不高于行文本。
我错过了一些明显的把戏吗,还是有某种方法可以增加行高以允许表中更大的图像。
我发现了一种latex的方法,但这依赖于手动建立表。我有很多图像,并且如果可能的话,我更愿意使用数据框方法来做到这一点。