首页 > 解决方案 > 如何在 R markdown 中将 LaTeX 符号添加到 fig.cap?

问题描述

有没有办法\infty在 R markdown 中添加 LaTeX 符号,比如无穷大图标题?

我可以让 LaTeX 文本格式正常工作,但我想不出一种使用符号的方法。

这是一个使用 LaTeX 文本格式的工作示例:

---
output: 
  pdf_document:
    fig_caption: yes
---

```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(
  echo=FALSE,
  message=FALSE,
  warning=FALSE,
  fig.align = 'center'
  )
```

## Testing LaTeX syntax within captions

```{r pressure, fig.cap="\\label{testPlot}This caption has LaTeX with 
{\\small small text} and some {\\footnotesize footnote text and 
\\textbf{bold footnote}} and \\textit{italic}"}
plot(pressure)
```

我已经尝试了所有我能想到的组合,但都没有奏效。例如,双转义\\infty、括号{\infty}、括号内的双转义{\\infty}、使用内联 LaTeX $\infty$、内联转义等。

任何建议将不胜感激。

标签: rlatexr-markdown

解决方案


$\\infty$作品。您需要转义\in\infty并且 IIRC 这是一个数学模式符号,因此您也需要调用它。

```{r pressure, fig.cap="\\label{testPlot}This caption has LaTeX with {\\small small text} and some {\\footnotesize footnote text and \\textbf{bold footnote}} and \\textit{italic} and $\\infty$"}
plot(1:10)
```

推荐阅读