r - 是否可以为代码块生成的表(而不是图形)设置Fig.sap?

标签 r latex knitr caption xtable

我有一个由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 的字符向量传递给 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}

关于r - 是否可以为代码块生成的表(而不是图形)设置Fig.sap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35407344/

相关文章:

R正则表达式匹配已知字符以外的东西

r - Predict.svm 错误 : test data does not match model

r - 基于 R 中 beta分散() 多元分散体标记 PCoA 的质心

r - 在 xtable 中处理 Latex 反斜杠

latex - LaTeX 中的多个目录

r - knitr 中的 dygraph 不工作

javascript - Shiny - 动态生成的输入

latex - 如何将/tableofcontents 拆分为两列或更多列?

r - 如何在 R markdown 中保留表 "here defnitely"

r - knitr:for循环条件有什么办法可以包含Sexpr吗?