How to change bibliography style in Rmarkdown? - r

I am trying to change the style of my bibliography in Rmarkdown. I followed this solution but nothing happens in my case.
This is my code:
---
title: "Tilte"
author:
- name: Rollo99
abstract: |
Abstract
keywords: whatever
date: "`r Sys.Date()`"
citation_package: natbib
bibliography: library.bib
biblio-style: abbrvdin
references:
link-citations: yes
linkcolor: blue
output:
rticles::elsevier_article:
number_sections: yes
header-includes:
- \setcitestyle{numbers}
- \usepackage{amsmath}
- \usepackage{hyperref}
- \usepackage{graphicx}
- \usepackage[section]{placeins}
- \usepackage{float}
- \usepackage[font=small, skip=1pt]{caption}
- \usepackage[labelfont=bf]{caption}
- \usepackage{amssymb}
- \usepackage{inputenc}
- \usepackage{placeins}
- \usepackage{blindtext}
- \usepackage{setspace}
- \usepackage[top=3cm, bottom=3cm, left=3cm, right=3cm]{geometry}
- \usepackage{amsmath}
- \usepackage{amssymb}
- \usepackage{mathrsfs}
- \usepackage{longtable}
- \usepackage{graphicx}
- \usepackage{ragged2e}
- \usepackage{csquotes}
- \usepackage[bottom]{footmisc}
- \usepackage{xpatch}
- \setlength\parindent{0pt}
- \usepackage{appendix}
I downloaded and saved abbrvdin.bst in the same repository as the bibliography from here.
What am I doing wrong?
Thanks

The elsevier template does not support this, see the code on github.
You can just use plainmat or elsevier-harv.
A solution is to clone the repository and manipulate the file to your need. In addition to that you can raise a pull request.

Related

Compiling latex document in R Markdown

I am trying to compile a latex document in R markdown using R studio. These are the header options -
---
header-includes:
- \usepackage{float}
- \usepackage{wrapfig}
- \usepackage{graphicx}
- \usepackage{lipsum}
- \usepackage[fontsize=12pt]{scrextend}
- \usepackage{fontspec}
- \newcommand*{\bibfont}{\footnotesize}
- \PassOptionsToPackage{dvipsnames}{xcolor}
- \usepackage[dvipsnames]{xcolor}
- \usepackage{etoolbox}
- \defbibheading{bibliography}[\textcolor{Blue}\refname]{}
- \usepackage{blindtext}
- \usepackage{needspace}
- \usepackage{mwe}
output:
pdf_document:
latex_engine: xelatex
fig_caption: true
citation_package: biblatex
bibliography: Gibbs.bib
mainfont: ArialMT
geometry: margin=0.70in
---
And this is the error I get -
! Undefined control sequence.
<recently read> \defbibheading
Any help? Thanks!
The problem is that while rmarkdown will automatically load the biblatex package due to your citation_package: biblatex option, it will do so only after it has already processed your header includes. This means you can't directly use a macro like \defbibheading{} from the biblatex package in your header-includes.
As a workaround, you could try
---
header-includes:
- \usepackage{float}
- \usepackage{wrapfig}
- \usepackage{lipsum}
- \usepackage[fontsize=12pt]{scrextend}
- \usepackage{fontspec}
- \PassOptionsToPackage{dvipsnames}{xcolor}
- \usepackage[dvipsnames]{xcolor}
- \usepackage{etoolbox}
- \AtBeginDocument{\renewcommand*{\bibfont}{\footnotesize}\defbibheading{bibliography}[\textcolor{blue}{\refname}]{}}
- \usepackage{blindtext}
- \usepackage{needspace}
- \usepackage{mwe}
output:
pdf_document:
keep_tex: true
latex_engine: xelatex
fig_caption: true
citation_package: biblatex
bibliography: Gibbs.bib
mainfont: ArialMT
geometry: margin=0.70in
---
test

strange symbols generated from rmarkdown when I use Chinese characters in ggplot2

Recently, I encounter a problem in Rmarkdown.
When I add Chinese characters into xlab() and ylab() in ggplot2. The pdf document generated by rmd will display strange ...... symbol. However, I try to search useful something and the result told me I should add dev: cairo_pdf. Ok, after I add the code to YAML, the new error strange symbols occur again. It displays another strange symbols of □□□.
I want to ask for help from someone who may pay attention to my quesiton. Could you help me? Thank you very much. And here my test code:
---
title: "test.Rmd"
author: "author"
documentclass: ctexart
output:
rticles::ctex:
fig_caption: yes
number_sections: yes
toc: no
dev: cairo_pdf
word_document: default
keywords:
header-includes: \usepackage{booktabs} \usepackage{longtable} \usepackage{array} \usepackage{multirow}
\usepackage{wrapfig} \usepackage{float} \floatplacement{figure}{H}
---
library(ggplot2)
ggplot(cars,aes(speed,dist)) +
geom_line()+xlab("速度\nSpeed") + ylab("距离\nDist")
Sorry, I cannot replicate your images. I just altered the header-includes and included the figure in a code chunk. Did you install xelatex and TeX Live?
Here is the code that worked fine for me:
---
title: "test.Rmd"
author: "author"
documentclass: ctexart
output:
rticles::ctex:
fig_caption: yes
number_sections: yes
toc: no
dev: cairo_pdf
word_document: default
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \floatplacement{figure}{H}
---
```{r}
library(ggplot2)
ggplot(cars,aes(speed,dist)) +
geom_line()+xlab("速度\nSpeed") + ylab("距离\nDist")
```
-output

Harvard citation format in R markdown

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
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:

R Markdown - remove left-sided header in pdf output

I am trying to create an automated report in rmarkdown for business partners and I am a bit stuck on how to set up the headers using the Latex package fancyhdr.
The report includes a table of contents set to level 1 headers, but there are sub-sections in the report that are created using level 2 headers.
When I generate the PDF the fancy header has the level 1 header on the right header (which is fine), the message I set in the central header (also fine), and the sub-section (level 2 header) in the left header.
I would like to remove this, but the documentation is very vague as to how to do so - I've just spent a considerable amount of fruitless time trying to get this to work.
Here are the YAML settings at the top of the R Markdown document:
title: "Report Title"
author: "Authors"
date: 'Date'
output:
pdf_document:
latex_engine: xelatex
toc: true
toc_depth: 1
header-includes:
- \usepackage{fontspec}
- \setmainfont{Gotham Book}
- \usepackage{booktabs}
- \usepackage[tocflat]{tocstyle}
- \usetocstyle{standard}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{Center Message}
- \fancyfoot[CO,CE]{Footer Message}
- \fancyfoot[LE,RO]{\thepage}
---
These are the "left-odd" and "right-even" headers. If you set them to nothing using \fancyhead[LO,RE]{} they will go away:
---
title: "Report Title"
author: "Authors"
date: 'Date'
output:
pdf_document:
latex_engine: xelatex
toc: true
toc_depth: 1
header-includes:
- \usepackage{fontspec}
- \usepackage{booktabs}
- \usepackage[tocflat]{tocstyle}
- \usetocstyle{standard}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{Center Message}
- \fancyfoot[CO,CE]{Footer Message}
- \fancyfoot[LE,RO]{\thepage}
- \fancyhead[LO,RE]{}
- \usepackage{blindtext}
---
\blinddocument
(I have removed your font and inserted some sample text to show the effect.)

part of square root latex equation dissappears in pdf rendering from RStudio's rmarkdown

When I use this code to make a square root in my pdf document (rendered by rmarkdown):
---
title: "Test"
author: "test test"
geometry: margin=1in
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
number_sections: yes
toc: yes
toc_depth: 3
html_document:
css: tables.css
number_sections: yes
theme: cerulean
toc: yes
toc_depth: 3
header-includes:
- \usepackage[dutch]{babel}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot[LE,RO]{this is a fancy foot}
- \usepackage{dcolumn}
- \usepackage{here}
- \usepackage{longtable}
- \usepackage{caption}
- \captionsetup{skip=2pt,labelsep=space,justification=justified,singlelinecheck=off}
subtitle: test test test
fontsize: 12pt
---
$$ S_E\text{=}S_x\sqrt{\text{(}\text{1}\text{-}r_{xx}\text{)}} $$
this is the result:
Notice the strange looking square root. Does anyone know what's going wrong here in my code?
I found the solution to this problem here:
https://tex.stackexchange.com/questions/210153/pdftex-font-expansion-error-during-compilation
In the directory C:\Program Files\MiKTeX 2.9\miktex\bin\x64 I ran updmap.exe. After that the problem was solved.

Resources