如何在 Rmarkdown 中包含一个编号为 table 的 PNG 文件?

How can I include a PNG file as a numbered table in Rmarkdown?

我有一个 table 由外部程序生成的 PNG(或 PDF)图像,我想将其作为编号 table 包含在我的 Rmarkdown / Bookdown 文档中。 table 太复杂,无法直接使用 kable 或 FlexTable 等生成

我目前有

```{r table24, tidy=FALSE, echo=FALSE} 
kable(c(),caption="My table.")  
knitr::include_graphics("images/my-table.png") 
```

这适用于 HTML 和 DOC 输出,但不适用于 PDF(图像通过,但未列为 table)。

有在 table 中包含图像的在线示例,但这里的图像是 table。

请问有更好的解决方案吗?

你可以用 LaTeX 做到:

---
title: "Table"
header-includes:
- \usepackage {caption}
output:
  pdf_document
---

\begin{table}[hbtp]
\centering
\caption{Big table which I have}  
\includegraphics{your_table.png}
\caption*{Put comments here if you want}
\end{table}

P.S.:这里有一些有用的参数,对你以后的工作也有帮助:

\includegraphics[width=1cm, height=1cm, angle = 10, keepaspectratio]{your_pic.png}

你可以这样做

![caption](relative_path)