使用 natbib 时将参考书目放在附录之前

Place bibliography before Appendix when using natbib

我有以下文件。

---
title: "What comes after the bibliography?"
bibliography: refs.bib
header-includes:
  - \usepackage{natbib}
  - \setcitestyle{numbers}
  - \setcitestyle{square}
output: 
  pdf_document:
    citation_package: natbib
    latex_engine: lualatex
    keep_tex: yes
---

# A

This document may use knitr[@pKnitr].

# References

<div id="refs"></div>

# Appendix

`1+1` evaluates in R to `r 1+1` (for more information, see [@pRmarkdown])

我使用 citation()refs.bib 中创建了 bibtex 参考文献。

@InCollection{pKnitr,
  booktitle = {{Implementing Reproducible Computational Research}},
  editor = {Victoria Stodden and Friedrich Leisch and Roger D. Peng},
  title = {knitr: A Comprehensive Tool for Reproducible Research in {R}},
  author = {Yihui Xie},
  publisher = {Chapman and Hall/CRC},
  year = {2014},
  note = {ISBN 978-1466561595},
  url = {http://www.crcpress.com/product/isbn/9781466561595}
}

@Book{pRmarkdown,
  title = {{R Markdown Cookbook}},
  author = {Yihui Xie and Christophe Dervieux and Emily Riederer},
  publisher = {Chapman and Hall/CRC},
  address = {Boca Raton, Florida},
  year = {2020},
  note = {ISBN 9780367563837},
  url = {https://bookdown.org/yihui/rmarkdown-cookbook}
}

我想将参考书目放在附录之前。到目前为止,我已经尝试了以下方法,不幸的是没有运气。

最后一点,如果我的 Rmd 文件中有以下内容...

<!-- ... -->
# References

\bibliography{refs}

# Appendix

`1+1` evaluates in R to `r 1+1` (for more information, see [@pRmarkdown])

...它生成以下 LaTeX 文件。

% ...
\section{A}\label{a}}

This document may use knitr\citep{pKnitr}.

\hypertarget{references}{%
\section{References}\label{references}}

\bibliography{refs.bib}

\hypertarget{appendix}{%
\section{Appendix}\label{appendix}}

\texttt{1+1} evaluates in R to 2 (for more information, see
\citep{pRmarkdown})

  \bibliography{refs.bib}

\end{document}

因此 \bibliography{refs.bib} 现在添加了两次,导致 Citations multiply defined 错误。

如何使用 natbib 在我的附录之前添加参考书目?

如果你使用 markdown 的所有干扰,你可以更灵活地放置参考书目:

---
title: "What comes after the bibliography?"
header-includes:
  - \usepackage{natbib}
  - \bibliographystyle{plainnat}
  - \setcitestyle{numbers}
  - \setcitestyle{square}
output: 
  pdf_document:
    latex_engine: lualatex
    keep_tex: yes
---

# A

This document may use knitr \cite{pKnitr}.

\bibliography{refs}

# Appendix

`1+1` evaluates in R to `r 1+1` (for more information, see \cite{pRmarkdown})