Home > Back-end >  How can I include a PNG file as a numbered table in Rmarkdown?
How can I include a PNG file as a numbered table in Rmarkdown?

Time:11-03

I have a table generated by an external program as a PNG (or PDF) image and I'd like to include it as a numbered table in my Rmarkdown / Bookdown document. The table is too complex to generate directly using kable or FlexTable etc.

I currently have

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

This works for HTML and DOC output, but not PDF (the image comes through, but it is not listed as a table).

There are online examples of including images within a table, but here the image IS the table.

Is there a better solution please?

CodePudding user response:

You can do it with 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}

enter image description here

P.S.: here are some useful parameters, which can also help you in the future work:

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

CodePudding user response:

You can do it with this

![caption](relative_path)
  • Related