【问题标题】:Is it possible to set fig.scap for table (instead for figure) genrated by a code chunk?是否可以为代码块生成的表(而不是图)设置 fig.sap?
【发布时间】:2016-02-15 10:48:11
【问题描述】:

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

对于生成的绘图,此标签可以通过块选项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}

【问题讨论】:

    标签: r latex knitr caption xtable


    【解决方案1】:

    要定义要在图形列表中使用的“短标题”,请将长度为 2 的字符向量传递给 xtablecaption 参数。来自?xtable

    caption:包含表格标题或标题的长度为 1 或 2 的字符向量。如果length为2,则第二项是LaTeX生成“表列表”时使用的“短标题”

    示例:

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

    【讨论】:

      猜你喜欢
      • 2019-05-22
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      相关资源
      最近更新 更多