3

I am trying to switch from LaTeX to RMarkdown+bookdown when writing a paper that includes tables and figures. One main motivation is to be able to create both Word documents and PDF documents.

For word_document2, how can I add a figure title/caption above the figure as well as figure notes below the same figure?

Here is how I would do it in LaTeX (and it would be convenient to continue using LaTeX as I am transferring everything over from LaTeX to RMarkdown).

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

More broadly, is it possible to use LaTeX code with word_document2?

Note that my preamble currently looks like:

---
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
---

And I am currently able to get the caption above the figure, but just for the pdf_document2 (see Caption above figure using knitr (LaTeX/PDF)):

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

This doesn't seem to work when creating the Word document.

bill999
  • 2,147
  • 8
  • 51
  • 103

1 Answers1

3

yihui says in his documentation¹ we can use the officedown² package to influence word layouts. It has the Plot- option topcaption: you can set it to true as shown below.

---
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)

``

this should give you a docx with figure captions on top.

user12256545
  • 2,755
  • 4
  • 14
  • 28
  • Thank you. This produces figure captions on top. Does it also produce figure notes on bottom (meaning the same figure has both a figure caption above it and figure notes below it)? – bill999 Oct 20 '21 at 14:27