Use image as table in RMarkdown?

2019-07-25 17:57发布

问题:

I appreciate that what I'm trying to do will sound silly, but please bear with me. I want to insert an existing image (a PNG) of a table into an RMarkdown document that will be turned into a pdf. Is there any way I can do this and have the image treated as a table for numbering purposes? That is, obviously I could do

![A caption for my table](my_table_as_image.png)

but the problem is that it will be numbered as e.g. Figure X, not Table Y. I would like it to be named/numbered as a table.

Thank you for any advice.

回答1:

Looks like I got to a way to do it with kable with some inspiration...this still has two horizontal lines but that's ok for the moment:

```{r echo=F, warning=F}
temp.df = data.frame(image="![](mytable.png)")
temp.mat <- as.matrix(temp.df)
colnames(temp.mat) <- NULL
knitr::kable(temp.mat, caption="This is my caption")

```