是否可以为代码块生成的 table(而不是图形)设置 fig.scap?

Is it possible to set fig.scap for table (instead for figure) genrated by a code chunk?

我有一个 table 由 knitr 代码块生成。 table 使用 xtable 打印。它的标题设置在 xtable 函数中。此标签太长,无法显示在文档开头的 table 列表中。因此,我想设置一个短标签,用于代替此列表中的长标签。

对于生成的绘图,可以通过块选项 fig.scap 设置此标签,但是当我尝试将其用于 table 时,长标签仍保留在 table 列表中s.

我想我可以在代码块之外使用 \captionof{table}[short label]{long label} 来处理这个问题,但这不是一个非常简单的方法,我担心我会遇到问题 table和它的标题在一起。有更好的方法吗?

代码(含人工数据):

\documentclass[a4paper,12pt, english]{article}

\usepackage{capt-of}

\begin{document}
\listoffigures
\listoftables
\section{Intoduction}
<<Chunk1, results="asis", echo=FALSE, fig.scap= "short caption - tab">>=
library(xtable)
print(xtable(head(iris), caption="long caption of the table"))
@

<<Chunk2, results="asis", echo=FALSE,fig.align="center", fig.cap = "Long caption of the figure", fig.scap= "short caption - fig">>=
plot(iris[,1:2])
@

\end{document}

要定义要在图表列表中使用的 "short caption",请将长度为 2 的字符向量传递给 xtablecaption 参数。来自 ?xtable:

caption: Character vector of length 1 or 2 containing the table's caption or title. If length is 2, the second item is the "short caption" used when LaTeX generates a "List of Tables"

示例:

\documentclass{article}
\begin{document}
\listoftables
<<echo = FALSE, results = "asis">>=
xtable::xtable(head(iris), caption = c("Long Caption", "Short"))
@
\end{document}