Is there a way to select the language for Rmarkdown? For example, I'm writing an assignment in portuguese, but table captions will come off as Table 1: something.
In latex files you can just add \usepackage[brazil]{babel}. Is there an equivalent option for rmarkdown?
I found the answer in the TeX SE site: https://tex.stackexchange.com/questions/171711/how-to-include-latex-package-in-r-markdown.
You can just include packages with a header-includes argument.
---
title: "Title"
author: "Me"
header-includes:
- \usepackage[brazil]{babel}
output:
pdf_document
---
Related
I am currently writing my thesis in RMarkdown using the template Oxforddown (which is ultimately based on bookdown). I have been reading the documentation but I confess I am lost. I am trying to create a table that contains an overview of the experimental conditions and items I used in my empirical study, so it is not data that I can load into R and then use the kable function on. However, I do not understand how I could generate such a table. Generating RMarkdown tables outside code chunks seems to work, but then the captions and referencing are very different than the rest of the captions used so far, which I usually set up within code chunks. Example below:
{r pilot-short7, echo=FALSE, fig.scap="Pilot 2: ....", out.width="65%", message=FALSE, fig.pos='H', fig.align = 'center'}
When I am trying to include RMarkdown tables inside a code chunks, things go wrong. What would my options be?
Any help would be very much appreciated!
I prepared a markdown template for you.
Here I made a table with flextable library.
But you can use another, which you like, f.e.: kableExtra, gt etc.
As you can see, you should put \label{tab:caption} and after refer in the text by \ref{tab:caption}.
---
title: "Hello World"
header-includes:
- \usepackage{caption}
output:
pdf_document:
latex_engine: xelatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, include = FALSE}
library(flextable)
library(dplyr)
table2 <- flextable(mtcars[1:5, 1:6])
```
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
\begin{table}[hbtp]
\captionof{table}{Text of the caption.}
\label{tab:caption}
`r table2`
\end{table}
Table \ref{tab:caption} is the baddest table in the World
I created my lecture notes in pdf format using RMarkdown but it has many subheaders. Because of this, I want to create two different table of contents: first table of contents with 1 depth, then table of contents in 4 depth respectively.
Adding both toc_depth: 1 and toc_depth: 4 did not work.
My YAML header:
---
title: "Lecture Notes"
author: "x"
output:
pdf_document:
highlight: tango
toc: true
toc_depth: 4 #depth table of contents
number_sections: true
documentclass: article
classoption: a4paper
fontsize: 12pt
geometry: "right=1cm, left=1cm, top=1cm, bottom=3cm"
---
As far as I am aware, I don't believe two Table of Contents is possible. One thing you can try is if you don't want a certain heading numbered, you can do
## Including Plots {-}
Which heads it has a header, but doesn't number it in the TOC. Here is the two output differences
without {-}
with {-}
These can be used in places like the Preface, about the authors, etc.
This is not a perfect solution (maybe some with more knowledge could automate this).
The solution works if the intermediate latex file is kept and a short table of contents is manually added using the shorttoc package.
Adding shortdoc:
...
\documentclass[
]{book}
\usepackage{shorttoc}
...
And than adding it between title and TOC:
\shorttableofcontents{〈title 〉}{〈depth 〉}
Due to different journal requirements, I need to frequently change certain text styles within Rmarkdown from one kind to another. For instance, here is an example Rmarkdown document.
---
title: "Changing format of Rmarkdown"
author: "Paul Hargarten"
date: "5/9/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an $\mathcal{R}$ Markdown document. Markdown is a simple formatting syntax for authoring **HTML**, **PDF**, and **MS Word* documents. For more details on using $\mathcal{R}$ Markdown see <http://rmarkdown.rstudio.com>. $\matcal{R}$ is based on $\mathcal{S}$.
When you click the `Knit` button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. Calculate a `summary` as follows:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example: `r plot(pressure)`.
Without searching for the exact phrase, suppose that I would like to find and replace the following items:
1. Change items in bold ** ... ** to italics _ ... _.
2. Change items that look like $\mathcal{ ... }$ to bold ** ... **.
3. Change special font `...`, except those that start with r, to \code{ ... }.
4. Add dollar signs to `r ... ` => $`r ... `$.
Is this possible to use regex to make these formatting style changes in
Rmarkdown? Thanks!
This is something that LaTeX is good at, but it will be harder with Markdown.
If you were entirely in LaTeX, you could define your own macros based on the uses for that markup. For example,
\newcommand{\booktitle}[1]{\textbf #1}
used for book titles as \booktitle{The Book}. If you wanted to switch book titles to italic, you'd just change that definition.
Doing this in R Markdown is possible, but you wouldn't be able to mark book titles using **. You could do it (you can embed LaTeX in R Markdown), but it's ugly. For example,
---
title: Using LaTeX
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\newcommand{\booktitle}[1]{\textbf{#1}}
This is \booktitle{The Book}.
Once you're doing this, you might as well switch to Sweave-like *.Rnw format, or all the way to LaTeX.
As the title says, I use Rmarkdown to write a document.
I use the following text at the top of the .Rmd document:
---
title: "Title"
author: "Me"
date: "September 10, 2018"
output:
pdf_document: default
html_document: default
bibliography: bibliography.bib
---
And then I use the following code in my bibliography.bib document, which, according to the document properties is a bibtex file:
#article{Brooks98,
author={ Brooks, S. P. and Gelman, A.},
title={Interface foundation of america general methods for monitoring convergence of iterative simulations general methods for monitoring convergence of iterative simulations},
year={1998},
journal={Journal of Computational and Graphical Statistics},
volume=7,
issue=4,
pages=434-455
}
I expect to get
Brooks, S. P. and Gelman, A. 1998
but instead I get
Brooks, S. P., and A. Gelman. 1998
My question is, what causes this and how do I solve the problem?
You have to change your citation style. One simple solution would be to use bibtex together with natbib and apalike:
---
title: "Title"
author: "Me"
date: "September 10, 2018"
output:
pdf_document:
citation_package: natbib
html_document: default
bibliography: bibliography.bib
biblio-style: apalike
---
(Note that you will have to use pages={434-455} for this to work.)
If there are other aspects of the citation style that do not fit, you can have a look at this answer for ways of finding other styles. Another alternative would be biblatex.
The default, which I am less familiar with, is to use pandoc-citeproc, which uses CSL files to define the style. See here for resources about additional CSL styles: https://citationstyles.org/
I'm using R markdown for a university assignment. I'd like to have questions number/letters left aligned on my document, but rmarkdown is adding spaces before "a)" and "b)", which I'd like to be aligned with the rest of my text.
---
title: "Untitled"
author: "dsn084"
date: "26 March 2017"
output: pdf_document
---
This is a paragraph.
a) this is part a.
b) this is part b.
And my output ...
As you are using output: pdf_document, the rmarkdown document will be converted into latex before pdf, so you can use latex instructions to accomplish that.
flushleft will do it. Example:
This is a paragraph.
\begin{flushleft}
a) this is part a.
b) this is part b.
\end{flushleft}