使用 r markdown/knitr 抑制 pdf 输出中的自动数字编号



我正在用R markdown(.rmd)写一个文档。我希望能够编织Word和PDF输出。我在数字编号方面遇到困难。使用PDF输出,数字会自动编号(通过fig.lp的Latex输出?但是数字没有在单词中编号.

经过大量搜索,我找到了将在 Word 中提供图形编号的代码 - 但现在我在编织 PDF 时得到了双页编号。我是新手,所以我无法插入图像。但图形标题如下所示:

图1.图1.呸

��

有没有办法禁止 PDF 的自动编号?

这里提出了类似的问题,但没有给出解决方案。我的 YAML 标题和数字编号 chuck 包含在下面。

亚姆:

output:
  pdf_document:
    fig_caption: yes
    keep_tex: yes
  word_document:
    fig_caption: yes

图编号代码(通过 http://galahad.well.ox.ac.uk/repro/找到)

figRef <- local({
    tag <- numeric()
    created <- logical()
    used <- logical()
    function(label, caption, prefix = options("figcap.prefix"), 
        sep = options("figcap.sep"), prefix.highlight = options("figcap.prefix.highlight")) {
        i <- which(names(tag) == label)
        if (length(i) == 0) {
            i <- length(tag) + 1
            tag <<- c(tag, i)
            names(tag)[length(tag)] <<- label
            used <<- c(used, FALSE)
            names(used)[length(used)] <<- label
            created <<- c(created, FALSE)
            names(created)[length(created)] <<- label
        }
        if (!missing(caption)) {
            created[label] <<- TRUE
            paste0(prefix.highlight, prefix, " ", i, sep, prefix.highlight, 
                " ", caption)
        } else {
            used[label] <<- TRUE
            paste(prefix, tag[label])
        }
    }
})

然后在块选项中调用它,如下所示:

```{r, echo=FALSE, message=FALSE, fig.width=6, fig.cap=figRef("Ex-Airfoil", "Example NACA Airfoil")}

有没有办法抑制PDF的自动编号?

确定。为输出格式添加一个 format 变量,并在 figref 中添加该格式的处理程序。使用 RStudio 预览版,您可以使用format <- knitr::opts_knit$get("out.format")但对于发布版本,您需要手动设置它。
然后在figref()添加您想要的输出的任何内容......

    if ( format == "latex" ) return( caption )
    if (!missing(caption)) {
    --- >8 ---

就个人而言,我会使用预览版和 switch 语句来处理。沿着 https://stackoverflow.com/a/27321367/173985 的路线。

相关内容

最新更新