bookdown - 如何在使用word_document2时将图标题放置于图上方,而图注放置于图下方?

3

我想要将写论文时需要用到的表格和图表从LaTeX转换成RMarkdown+bookdown。其中一个主要动机是为了能够创建Word文档和PDF文档。

对于word_document2,我该如何在图表上方添加图表标题/说明,并在相同的图表下方添加注释?

以下是我在LaTeX中的做法(因为我正在将所有内容从LaTeX转移到RMarkdown中,所以继续使用LaTeX会很方便)。

\begin{figure}
\caption{Figure Title...}
\label{figure_label}
\vspace*{.2cm}
\includegraphics[width=7in]{figure_name.png}\\
\caption*{Figure Notes...}
\end{figure}

更广泛地说,是否有可能在word_document2中使用LaTeX代码?
请注意,我的导言目前看起来像:
---
title: "..."
author: "..."
date: "10/14/2021"
output:  
  bookdown::word_document2:
    number_sections: false
  bookdown::pdf_document2: 
    number_sections: false    
header-includes:
   - \usepackage{floatrow}
   - \floatsetup[figure]{capposition=top}    
citation_package: default
bibliography: ../references.bib    
always_allow_html: true
---

我目前能够获得图像上方的标题,但仅适用于pdf_document2(请参见Caption above figure using knitr (LaTeX/PDF)):

```{r figure-label, fig.cap="Figure Title", fig.width=6, fig.height=3.7, fig.align="center"}
...

在创建Word文档时,这似乎不起作用。

1个回答

3

yihui在他的文档¹中提到,我们可以使用officedown²包来影响word版面。它有一个选项topcaption:您可以将其设置为true,如下所示。

---
title: "..."
author: "..."
date: "10/14/2021"
output:  
  officedown::rdocx_document: 
    plots:
      style: Normal
      align: center
      topcaption: true
  bookdown::pdf_document2: 
    number_sections: false
header-includes:
   - \usepackage{floatrow}
   - \floatsetup[figure]{capposition=top}    
citation_package: default
---




```{r figure-label, fig.cap="Top Caption", fig.width=6, fig.height=3.7}
plot(rnorm(1000,300,32))

library(officedown)

``

这样做可以让您得到一个带有图片标题的docx文档。


谢谢。这会在顶部生成图标题。它是否还会在底部生成图注(意味着同一图有上方的图标题和下方的图注)? - bill999

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接