如何将数字引用为 table?

How to refer a figure as a table?

我知道,这可能不是最明智的想法,但我需要插入一个 table 作为 figure/screenshot (.png),但将其称为 table标题。可能吗?

我的 gaol 与 here 基本相同,唯一的区别是我在 RStudio 中使用 rmarkdown、knitr 和 bookdown。理想情况下,该解决方案应该适用于 PDF 和 HTML 输出(尽管现在 PDF 对我来说更重要)。

作为 hack,您可以创建一个虚拟的 table,它以极小的字体大小打印,只是为了获得 table 标题,然后在同一块中添加实际的 table 要打印的图像。例如:

---
title: Document Title
output: 
  bookdown::pdf_document2:
    toc: no
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(xtable)
options(xtable.include.rownames=FALSE, xtable.comment=FALSE)

# Dummy table function
dt = function(label, caption=NULL) {
  print(xtable(setNames(data.frame(x=numeric()), " "),
               caption=caption,
               label=paste0("tab:", label)), 
        hline.after=NULL,
        booktabs=FALSE,
        size="\fontsize{0.1pt}{0.1pt}\selectfont")
}
```

Lorem Ipsum is simply dummy text of the printing and typesetting industry. As you can see, Table \@ref(tab:lab1) shows something. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. 

```{r, lab1, results="asis", fig.align="center", out.width="6in"}
dt("lab1", "This is table 1")
include_graphics("tab1.png")
```

Now for some more text and then here is Table \@ref(tab:lab2).

```{r, lab2, results="asis", fig.align="center", out.width="4.5in"}
dt("lab2", "This is table 2")
include_graphics("tab2.png")
```

在下面,您可以看到输出文档的样子。如您所见,标题和 table 之间有一些额外的 space,因为不可见的虚拟 table 占据了少量垂直 space。希望对乳胶有更好了解的人可以建议如何摆脱它 space。


我有,当时没看到这个问题。如果您对顶部和底部仍然有水平线没问题,您可以做一个 table,只包含您要显示的 table 的图像,如下所示:

```{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")

```

仍然是 hack,但比当前接受的答案少了一些工作。