2

I am using R markdown for a document, however I just have to do some minor tweaks to my citations.

Firstly, is there a package which will put my BibTeX references in Harvard format?

And secondly, how can I get the author's surname and the year to be seperated by a comma within my in-text citations?

Here is one of the references in my BibTex file

@article{schwarz1978estimating,
  title={Estimating the dimension of a model},
  author={Schwarz, Gideon and others},
  journal={The annals of statistics},
  volume={6},
  number={2},
  pages={461--464},
  year={1978},
  publisher={Institute of Mathematical Statistics}
}


When I in-text reference this, it generates (Schwarz 1978). I would like a comma to seperate the surname and the year.

I've also added my YAML if that is needed

### Adding additional latex packages:
header-includes:
   - \usepackage{rotating, caption} \DeclareMathOperator*{\argmin}{argmin}
   - \usepackage{booktabs}
   - \usepackage{longtable}
   - \usepackage{array}
   - \usepackage{multirow}
   - \usepackage{wrapfig}
   - \usepackage{float}
   - \usepackage{colortbl}
   - \usepackage{pdflscape}
   - \usepackage{tabu}
   - \usepackage{threeparttable}
   - \usepackage{threeparttablex}
   - \usepackage[normalem]{ulem}
   - \usepackage{makecell}
   - \usepackage{xcolor}

output:
  pdf_document:
    keep_tex: yes
    template: Tex/TexDefault.txt
    fig_width: 3.5 # Adjust default figure sizes. This can also be done in the chunks of the text.
    fig_height: 3.5
1
  • 1
    There are quite a few variations of Harvard citation styles. Easiest way is to use rticles package, such as csl: elsevier-harvard.csl. However, if rticles does not include the CLS variation you want, you may be able to find one fits it at zotero.org/styles. Jan 6, 2020 at 3:02

1 Answer 1

3

I rely on the standard (and very powerful) natbib package which many Rmd styles already add, and which you can generally add to whichever RMarkdown template you use (and you didn't say).

Quick example using my pinp package:

---
title: Example

author:
  - name: Dirk Eddelbuettel
    affiliation: a
address:
  - code: a
    address: Planet Earth

papersize: letter
fontsize: 12pt
one_column: true
bibliography: ref
output: pinp::pinp
---

# Introduction 

Two quick examples using natbib

- citet: \citet{schwarz1978estimating}
- citep: \citep{schwarz1978estimating}

For the rest, see the natbib documentation, either at source or contributed
such as https://gking.harvard.edu/files/natnotes2.pdf.

The body of that document comes out as follows:

enter image description here

2
  • I am using elsarticle. I have tried adding the natbib package to my YAML, but that doesnt seem to work. Any advice on how to add the package and specify the Harvard referencing format for my bibliography?
    – Tanga94
    Jan 5, 2020 at 23:58
  • 1
    A quick recursive grep in the rticles/rmarkdown/templates/elsevier_article directory reveals that natbib already is a supported option, see template.tex. You just need to turn it on. Jan 6, 2020 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.