【问题标题】:Is there a way to hide figure captions when using knitr and pandoc to create docx files?使用 knitr 和 pandoc 创建 docx 文件时,有没有办法隐藏图形标题?
【发布时间】:2014-01-24 10:10:44
【问题描述】:

我正在使用 knitr 和 pandoc 将报告写入 word(我们需要能够使用轨道更改等为 cmets 进行循环)。

到目前为止它运行得很好,但我发现情节都在底部带有字幕,我不想要字幕。虽然我可以在 word doc 中删除它们,但如果我可以阻止它们在代码中显示会更好。

所以对于markdown中的以下代码:

Test test test

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r fig.width=7, fig.height=6}
plot(cars)
```

然后我在 R 中运行以下代码:

library("knitr")

# Stackoverflow table test 1.html

knit2html("captiontest.rmd")

FILE <- "captiontest"

system(paste0("pandoc -o ", FILE, ".docx ", FILE, ".md"))

并且该图在 word 文档中的标题为“plot of chunk unnamed-chunk-2”

我知道我可以更改此标题,例如{r fig.width=7, fig.height=6, fig.cap='hello'},但我认为fig.cap=NULL 会将其隐藏。相反,它似乎使整个情节消失了。

情节是否需要有标题 - 我是否只需要浏览每个单词文档并手动删除它们?或者有没有办法隐藏它们?

【问题讨论】:

    标签: r markdown knitr pandoc


    【解决方案1】:

    有点肮脏的把戏,但是:

    您可以在有问题的块上设置fig.cap=""

    Test test test
    
    ```{r}
    summary(cars)
    ```
    
    You can also embed plots, for example:
    
    ```{r fig.width=7, fig.height=6, fig.cap=""}
    plot(cars)
    ```
    

    或者,您可以在 Rmd 文档开头的初始化块中一次为所有块设置 fig.cap=""

    Test test test
    
    ```{r options-chunk} 
    opts_chunk$set(fig.cap="")
    ``` 
    
    ```{r}
    summary(cars)
    ```
    
    You can also embed plots, for example:
    
    ```{r fig.width=7, fig.height=6}
    plot(cars)
    ```
    

    【讨论】:

    • 啊,鬼鬼祟祟,能够一次为所有这些设置它很有用。谢谢 :) (我觉得我应该试试看!)
    • 将 fig.cap 设置为 NULL 或 NA 感觉它们应该直观地提供相同的结果。
    • 我有代码(我去年从别人那里修改的)在我的数字上方创建了很好的编号标题。最近(我不记得什么时候了),我的人物也有他们下面的标题。为什么knit.hook 不覆盖:# number figures with zfn and make a pretty caption zfn = local({ i = 0 function(x) { i &lt;&lt;- i + 1 paste('&lt;b&gt;\n\nFigure ', i, ': ', x, '&lt;/b&gt;',sep = '') # wraps your caption in &lt;caption&gt;&lt;/caption&gt; } }) knit_hooks$set(fig.cap = function(before, options, envir) { if(before) zfn(options$fig.cap) })
    • @jessi 我认为您应该提出一个新问题。 :)
    猜你喜欢
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    • 1970-01-01
    • 2012-08-10
    • 2019-11-23
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    相关资源
    最近更新 更多