R bookdown - table-header 中的数学不起作用

R bookdown - math in table-header not working

克隆 bookdown-demo 后,我试图在 header 中得到一个带有一些数学运算的 table。在 html-output 中一切正常。在 PDF 输出中它被破坏了:

块:

```{r}
knitr::kable(
  head(cars),
  col.names = c("$y_{speed}$", "$y_{dist}$")
)
```

Bookdown - PDF:(在这里你可以看到错误的输出)

Rmarkdown - PDF:(结果符合预期)

Bookdown - HTML:(结果符合预期)

这是 Latex-Code bookdown 产生的:

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{knitr::}\KeywordTok{kable}\NormalTok{(}
  \KeywordTok{head}\NormalTok{(cars),}
  \DataTypeTok{col.names =} \KeywordTok{c}\NormalTok{(}\StringTok{"$y_\{speed\}$"}\NormalTok{, }\StringTok{"$y_\{dist\}$"}\NormalTok{)}
\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{r|r}
\hline
$y\_\{speed\}$ & $y\_\{dist\}$\
\hline
4 & 2\
\hline
4 & 10\
\hline
7 & 4\
\hline
7 & 22\
\hline
8 & 16\
\hline
9 & 10\
\hline
\end{tabular}

只需为 kable 使用参数 escape = F,因为 bookdown 中似乎有特殊字符的双重转义。