Search code examples
latexr-markdownfigurecaptionbeamer

Figures and figure caption side-by-side in RMarkdown Beamer


enter image description here

enter image description here

The plot in from http://xkcd.com/1132,and I just want one slide is figure caption beside the figure.

enter image description here

---
title: "CH6 Testing"
date: ""
fontsize: 9pt
header-includes:
 \usepackage{color}
 \usepackage{pdfpages}
 \usepackage{xeCJK}
 \setbeamertemplate{itemize items}[circle] ##可以改變符號的形狀
output:
 beamer_presentation:
  latex_engine: xelatex
---


## 6.10 The local FDR



```{r,echo=F,out.width='40%',fig.cap='While the frequentist only has the currently available data, the Bayesian can draw on her understanding of the world or on previous experience. As a Bayesian, she would know enough about physics to understand that our sun’s mass is too small to become a nova. Even if she does not know physics, she might be an empirical Bayesian and draw her prior from a myriad previous days where the sun did not go nova.',fig.margin=F,fig.align='center'}
knitr::include_graphics("./frequentists_vs_bayesians.png")
```

    

Solution

  • You could use the \captionof macro from the caption package to place the caption in a column besides the image:

    ---
    title: "CH6 Testing"
    date: ""
    fontsize: 9pt
    header-includes:
     - \usepackage{color}
     - \usepackage{pdfpages}
     - \usepackage{xeCJK}
     - \setbeamertemplate{itemize items}[circle] 
     - \usepackage{caption}
    output:
     beamer_presentation:
      latex_engine: xelatex
    ---
    
    
    ## 6.10 The local FDR
    
    \begin{columns}[onlytextwidth]
    \begin{column}{.4\textwidth}
    \includegraphics[width=\textwidth]{example-image-duck}
    \end{column}
    \begin{column}{.55\textwidth}
    \captionof{figure}{While the frequentist only has the currently available data, the Bayesian can draw on her understanding of the world or on previous experience. As a Bayesian, she would know enough about physics to understand that our sun’s mass is too small to become a nova. Even if she does not know physics, she might be an empirical Bayesian and draw her prior from a myriad previous days where the sun did not go nova.}
    \end{column}
    \end{columns}
    
    
    
        
    

    enter image description here