Rmd/Kntir:LaTeX环境中的Markdown引用

crs*_*rsh 18 latex r knitr r-markdown

我想threeparttable在Rmd/Knitr文档中创建一个并在表格底部添加注释.该表由一个块内的R函数创建results = "asis".我没有将该函数添加到工作示例中,因为它非常详细,并且问题从纯LaTeX代码中可见一斑.

这有效,结果看起来像预期的那样.

---
title: "Untitled"
output: pdf_document
header-includes:
- \usepackage{threeparttable}
- \usepackage{booktabs}
- \usepackage{longtable}
references:
- id: rao2001basic
  title: Basic Research in Parapsychology
  author:
  - family: Rao
    given: K.R.
  issued:
    year: 2001
  publisher: McFarland
  type: book
---

\begin{table}[h]
\centering
\begin{threeparttable}
\caption{A summary table of the cars dataset.}
\begin{tabular}{lrr}
\toprule
Descriptives & speed & dist\\
\midrule
Mean & 15.4 & 42.98\\
SD & 5.29 & 25.77\\
Min & 4 & 2\\
Max & 25 & 120\\
\bottomrule
\end{tabular}
\tablenotes{\item\textit{Note.} This table was created by @rao2001basic. }
\end{threeparttable}
\end{table}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

不幸的是,表格标题中的引用不起作用.如果我把它从LaTeX环境中拿出来,它可以正常工作,但不在里面.有没有办法在LaTeX环境中解析Markdown?

crs*_*rsh 0

我发现如果你愿意使用格式bookdown::pdf_document2(),你可以使用文本引用来解决这个问题,而不必搞乱 LaTeX:

---
title: "Untitled"
output: bookdown::pdf_document2
header-includes:
- \usepackage{threeparttable}
- \usepackage{booktabs}
- \usepackage{longtable}
references:
- id: rao2001basic
  title: Basic Research in Parapsychology
  author:
  - family: Rao
    given: K.R.
  issued:
    year: 2001
  publisher: McFarland
  type: book
---

(ref:tablenote)
This table was created by @rao2001basic.

\begin{table}[h]
\centering
\begin{threeparttable}
\caption{A summary table of the cars dataset.}
\begin{tabular}{lrr}
\toprule
Descriptives & speed & dist\\
\midrule
Mean & 15.4 & 42.98\\
SD & 5.29 & 25.77\\
Min & 4 & 2\\
Max & 25 & 120\\
\bottomrule
\end{tabular}
\tablenotes{\item\textit{Note.} (ref:tablenote)}
\end{threeparttable}
\end{table}
Run Code Online (Sandbox Code Playgroud)

这甚至在 R 中创建表时也有效:

```{r results = "asis"}
knitr::kable(mtcars[1:3, ], caption = "(ref:tablenote)")
```
Run Code Online (Sandbox Code Playgroud)