给出以下可重现的示例:
---
title: "pdf output by user defined tex template"
output:
pdf_document:
template: default.latex
#bibliography: bib.bib
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# About Pandoc metadata
https://pandoc.org/MANUAL.html#variables-for-latex
# Default tex templates
https://bookdown.org/yihui/rmarkdown-cookbook/latex-template.html
The default LaTeX template of Pandoc can be found at.
https://github.com/jgm/pandoc/tree/master/data/templates (named default.latex).
If you want to create your own template, you may want to start with this template.
# A reference to be cited in bibliography
here it is: @R-base
# References
! LaTeX 错误:出了点问题——可能缺少 \item。
另一方面:
我使用的模板(从)是 Pandoc 的默认 LateX 模板,位于: https://github.com/jgm/pandoc/blob/main/data/templates/default.latex
bib 文件仅包含以下条目:
@Manual{R-base,
title = {R: A Language and Environment for Statistical
Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2019},
url = {https://www.R-project.org},
}
我的问题是:
如何在用户定义的“模板”的情况下获得正确的引用列表(稍后我计划使用其他变量根据我的需要进行自定义)?
我应该在模板文件中输入一些内容吗? 最终如何做?
非常感谢任何帮助
听起来问题是您的自定义 LaTeX 模板与 R Markdown 中的参考书目设置之间的冲突。您应该修改自定义模板以正确处理参考书目。
打开您的自定义 LaTeX 模板。
找到应插入参考书目的部分,通常位于文档末尾附近。
添加以下行以合并参考书目:
$if(bibliography)$
$if(natbib)$
$if(biblio-style)$
\bibliographystyle{$biblio-style$}
$endif$
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
$endif$
$endif$
保存模板并在 R Markdown 文档中使用它。
如果我理解正确的话,这应该可以解决问题。