【问题标题】:Cannot render citations in a kable table无法在 kable 表中呈现引文
【发布时间】:2019-11-22 14:21:38
【问题描述】:

我无法使用默认的 pdf_document 或 bookdown::pdf_document2 或 html_document 在 kable 表中呈现引文。如下所示,在引用周围强制使用引号 (") 不会

(注意:“nocite”作为控件存在,.bib 中没有任何内容)。 文件'bib.bib'在同一目录下,如下:

@article{roy2019growth,
  title={Growth pattern and oxygen isotopic systematics of modern freshwater mollusks along an elevation transect: Implications for paleoclimate reconstruction},
  author={Roy, Rupsa and Wang, Yang and Jiang, Shijun},
  journal={Palaeogeography, Palaeoclimatology, Palaeoecology},
  pages={109243},
  year={2019},
  publisher={Elsevier}
}

代表代码

---
 output:
    bookdown::pdf_document2
# output: pdf_document
bibliography: bib.bib
---

Citation works, see [@roy2019growth]?


```{r results="asis"}
# using "asis" results
a <- c(1,2)
b <- c("@roy2019growth", "@nocite")
df <- data.frame(a,b)
kableExtra::kable(df)
```


```{r}
# without as is results
kableExtra::kable(df)
```

```{r}
# Try explicit '"' quotes
df <- data.frame(a,b = paste0('"',b,'"'))
kableExtra::kable(df)
```

# My Reference

会话信息

R 版本 3.5.3 (2019-03-11) 平台:i386-w64-mingw32/i386(32位) 运行于:Windows 7 x64 (build 7601) Service Pack 1

矩阵产品:默认

语言环境: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252

附加的基础包: [1] stats graphics grDevices utils datasets methods base

其他附加包: [1] kableExtra_1.0.1

通过命名空间加载(未附加): [1] Rcpp_1.0.1 rstudioapi_0.10 knitr_1.23 xml2_1.2.0 magrittr_1.5 hms_0.4.2
[7] rvest_0.3.4 munsell_0.5.0 viridisLite_0.3.0 colorspace_1.4-1 R6_2.4.0 rlang_0.4.0
[13] highr_0.8 stringr_1.4.0 httr_1.4.0 tools_3.5.3 webshot_0.5.1 xfun_0.8
[19] htmltools_0.3.6 yaml_2.2.0 digest_0.6.20 tibble_2.1.3 bookdown_0.9 crayon_1.3.4
[25] readr_1.3.1 glue_1.3.1 evaluate_0.14 rmarkdown_1.14 stringi_1.4.3 compiler_3.5.3
[31]pillar_1.4.2 scales_1.0.0 pkgconfig_2.0.2

从 .rmd 渲染 .md 会产生理想的输出

Citation works, see (Roy, Wang, and Jiang 2019)?

    # using "asis" results
    a <- c(1,2)
    b <- c("@roy2019growth", "@nocite")
    df <- data.frame(a,b)
    kableExtra::kable(df)

<table>
<thead>
<tr>
<th style="text-align:right;">
a
</th>
<th style="text-align:left;">
b
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
Roy, Wang, and Jiang (2019)
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
(<span class="citeproc-not-found"
data-reference-id="nocite">**???**</span>)
</td>
</tr>
</tbody>
</table>

    # without as is results
    kableExtra::kable(df)

<table>
<thead>
<tr>
<th style="text-align:right;">
a
</th>
<th style="text-align:left;">
b
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
Roy, Wang, and Jiang (2019)
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
(<span class="citeproc-not-found"
data-reference-id="nocite">**???**</span>)
</td>
</tr>
</tbody>
</table>

    # Try explicit '"' quotes
    df <- data.frame(a,b = paste0('"',b,'"'))
    kableExtra::kable(df)

<table>
<thead>
<tr>
<th style="text-align:right;">
a
</th>
<th style="text-align:left;">
b
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
"(<span class="citeproc-not-found"
data-reference-id="roy2019growth&amp;quot">**???**</span>);
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
"(<span class="citeproc-not-found"
data-reference-id="nocite&amp;quot">**???**</span>);
</td>
</tr>
</tbody>
</table>

My Reference
============

Roy, Rupsa, Yang Wang, and Shijun Jiang. 2019. “Growth Pattern and
Oxygen Isotopic Systematics of Modern Freshwater Mollusks Along an
Elevation Transect: Implications for Paleoclimate Reconstruction.”
*Palaeogeography, Palaeoclimatology, Palaeoecology*, 109243.

【问题讨论】:

  • 您是否尝试过先从 rmarkdown 生成 markdown 并查看 markdown 文档?
  • 是的,当从 .rmd 生成 .md 时,引用是在表中生成的。我已将生成的 .md 附加到 OP。

标签: r markdown r-markdown bookdown


【解决方案1】:

@hao-ye 找到了一个很好的解决方案,在 kable() 中指定 'markdown' 格式:enter code here

kableExtra::kable(dat,
      format = "markdown")

【讨论】:

    猜你喜欢
    • 2018-08-29
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多