LaTeX空白未显示在RMarkdown PDF中

nwwlzxa7  于 2023-10-13  发布在  其他
关注(0)|答案(3)|浏览(190)

我使用rmarkdownbeamer制作教学幻灯片。我试着在幻灯片中插入一个LaTeX方程,这个方程中有一些空格。

$Scott's \space pi = \frac{\% \space obs. \space agreements - \% \space exp. \space agreements}{1 - \% \space exp. \space agreements}$

当我将光标悬停在上面时,Rstudio会正确地预览公式,如您在下面的屏幕截图中所看到的:

然而,当我编织PDF时,空格不会出现,我得到了这个:

我是不是漏掉了什么?
我的markdown header如下:

---
title: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
author: "XXXXXXXXXXXXXXXXXXXXXXXXX"
institute: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
date: "XXXXXX"
output:
  beamer_presentation:
    incremental: true
    theme: "Berlin"
    colortheme: "dove"
    fonttheme: "structurebold"
    includes:
      in_header: preamble.tex
classoption: "aspectratio=169"

---

“preamble.tex”文件如下:

\usepackage{caption}
\captionsetup[figure]{labelformat=empty}
\setbeamercolor{frametitle}{fg=white,bg=black} %section slide title
\setbeamercolor{section in foot}{fg=white, bg=black} % footsections
\setbeamercolor{part title}{fg=white, bg=black}
\setbeamertemplate{footline}
{
 \hbox{%
  \begin{beamercolorbox}[wd=.33\paperwidth,ht=2.6ex,dp=1ex,left,leftskip=2ex]{section in foot} % footsection 1
    \usebeamerfont{section in foot}\insertshortauthor
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.33\paperwidth,ht=2.6ex,dp=1ex,center]{section in foot} % footsection 2
    \usebeamerfont{section in foot} \inserttitle
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.34\paperwidth,ht=2.6ex,dp=1ex,right,rightskip=2ex]{section in foot} % footsection 3
    \usebeamerfont{section in foot} XXXXXXXXXXXXXXXXXXXXX
  \end{beamercolorbox}}%

  \vskip0pt%
}

\setbeamertemplate{section page}{
  \centering
  \begin{columns}
  \begin{column}{\paperwidth}
  \begin{beamercolorbox}[sep=12pt,center]{part title}
    \usebeamerfont{section title}\insertsection\par
  \end{beamercolorbox}
  \end{column}
  \end{columns}
}
ovfsdjhp

ovfsdjhp1#

请不要使用数学模式的整个字,除了失踪的空格,字距调整都搞砸了!
相反,您可以使用amsmath包中的\text{...}宏(由beamer自动加载)

---
title: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
author: "XXXXXXXXXXXXXXXXXXXXXXXXX"
institute: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
date: "XXXXXX"
output:
  beamer_presentation:
    incremental: true
    theme: "Berlin"
    colortheme: "dove"
    fonttheme: "structurebold"
    includes:
      in_header: preamble.tex
classoption: "aspectratio=169"

---

- $\text{Scott's pi} = \frac{\text{\% obs. agreements} - \text{\% exp. agreements}}{1 - \text{\% exp. agreements}}$

vyswwuz2

vyswwuz22#

您可以添加

\text{ }

在方程里加一个空格。这应该适用于不同的格式。例如,如果要在符号%周围添加空格,可以考虑

\text{ \% }

在一个数学方程中。

pexxcrt2

pexxcrt23#

你需要使用它来为RMarkdown中的方程添加空间:http://www.emerson.emory.edu/services/latex/latex_119.html。在您的情况下,您只需将\space替换为\:
.Rmd文件示例:

---
title: "Equation with space"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

$$Scott's : pi = \frac{% : obs. : agreements - % : exp. : agreements}{1 - % : exp. : agreements}$$


产出:

![](https://i.stack.imgur.com/x4Whx.png)

相关问题