我有一个由knitr代码块生成的表。该表是使用xtable
打印的。它的标题是在 xtable
函数内设置的。该标签太长,无法显示在文档开头的表格列表中。因此,我想设置一个短标签,用于代替此列表中的长标签。
对于生成的图,可以通过 block 选项fig.scap
设置此标签,但是当我尝试将其用于表格时,长标签仍保留在表格列表中。
我想我可以在代码块之外使用 \captionof{table}[short label]{long label}
来处理这个问题,但这不是一个非常简单的方法,我'我担心将表格和标题粘在一起会出现问题。有更好的方法吗?
代码(带有人工数据):
\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}
最佳答案
要定义要在图形列表中使用的“短标题”,请将长度为 2 的字符向量传递给 xtable
的 caption
参数。来自 ?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}
关于r - 是否可以为代码块生成的表(而不是图形)设置Fig.sap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35407344/