Search code examples
latexr-markdowncaption

How to use greek letters in fig.caption using RMarkdown?


This code produces an error when I try to knit a pdf using RMarkdown in RStudio.

How can I write a greek letter in fig.caption as for example $\beta$?

---
title: "Untitled"
author: "SB"
date: "Thursday, January 29, 2015"
output: 
  pdf_document:
  fig_caption: yes
---


```{r var, echo=FALSE, fig.cap="Cars variation rate between year $t$ and $t-1$ for $0 < \beta < 1$"}
plot(cars)
```

Solution

  • In R, all backslashes inside character strings need to be doubled. "\\" becomes \.

    Try this:

    ---
    title: "Untitled"
    author: "SB"
    date: "Thursday, January 29, 2015"
    output: 
      pdf_document:
        fig_caption: yes
    ---
    
    ```{r var, echo=FALSE, fig.cap="Cars variation rate between year $t$ and $t-1$ for $0 < \\beta < 1$"}
    plot(cars)
    ```