Setting documentclass in Rmarkdown v2 - r

I would like to write my master thesis in RMarkdown v2 and I would be very glad if I could use a prepared LaTeX class.
Also I'd like to put some lines in the header and somehow add an abstract.
Can any1 knows how to do that?
Lines I'd be happy to have before \begin{document} are typically:
\usepackage[utf8]{inputenc}
\usepackage{polski}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tikz}
\usepackage{float} %pakiet do obsługi obrazków
\usepackage{graphicx} %pakiet do dodawania obrazków
\usepackage{tabularx} %pakiet do utrzymywania szerokości tabel równo z szerokością tekstu
\usepackage[T1]{fontenc} %przełączamy sie na fonty EC
\usepackage{dsfont}
% \usepackage[latin2]{inputenc} %kodowania polskich znakow ISO-8859-2 - mamy utf wyzej
\usepackage{xcolor} %pakiet do nadawania kolorów w \definecolor
\usepackage{listings} %pakiet do robienia tła jak w programie R
\lstset{language=R,%
% numbers=left,%
tabsize=3,%
numberstyle=\footnotesize,%
basicstyle=\ttfamily \footnotesize \color{black},%
escapeinside={(*#}{#*)}}
\usepackage{longtable}
\definecolor{ListingBackground}{rgb}{0.95,0.95,0.95}
\definecolor{ListingRule}{rgb}{0.7,0.7,0.7}
\lstdefinestyle{incode} %definiowanie stylu tła dla pisania kodu w R
{
basicstyle={\ttfamily\footnotesize},
backgroundcolor={\color{ListingBackground}},
frame={lr},
rulecolor={\color{ListingRule}},
framerule={2pt}
}
\usepackage{hyperref} %pakiet do dodawania hiperłącz
\hypersetup{colorlinks=true,
linkcolor=blue,
citecolor=blue,
urlcolor=blue}
%------------------------------------------------------------------------------%
\title{ o }
\author{Marcin Kosiński}
\supervisor{prof. dr hab. Michał Nowak}
\type{magisters}
\discipline{matematyka}
\monthyear{lipiec 2015}
\date{\today}
\album{123456}
And if possible after \begin{document} .
\begin{abstract}
some text
\end{abstract}
\tableofcontents
\listoffigures
\listoftables
Thanks for help in advance :) ! I'm aware I'll need to specify setting somehow in the begging of the Rmarkdown v2 document
---
title: "Magisterka"
author: "Marcin Kosiński"
date: "Tuesday, July 29, 2014"
output: pdf_document
documentclass: mini
includes:
in_header: headerMgr.tex
---
EDIT:
The soultion is good YAML specification:
---
title: "Magisterka"
author: "Marcin Kosiński"
date: "Tuesday, July 29, 2014"
output:
pdf_document:
includes:
in_header: header.tex
before_body: doc_prefix.tex
---

Based on this http://rmarkdown.rstudio.com/pdf_document_format.html, you need to include those lines:
---
title: "Magisterka"
author: "Marcin Kosiński"
date: "Tuesday, July 29, 2014"
output:
pdf_document:
includes:
in_header: header.tex
before_body: doc_prefix.tex
---
You need to remember to put all of the files (.Rmd, and all of .tex) in the same folder.

Related

LaTeX whitespace not showing up in RMarkdown PDF

I use rmarkdown and beamer to make teaching slides. I'm trying to insert a LaTeX equation in my slide, and this equation has a few spaces in it.
$Scott's \space pi = \frac{\% \space obs. \space agreements - \% \space exp. \space agreements}{1 - \% \space exp. \space agreements}$
When i hover on it with my cursor, Rstudio previews the equation correctly, as you can see in the screenshot below:
However, when I knit the PDF, the spaces don't appear, and I get this:
Am I missing something here?
My markdown header is as follows:
---
title: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
author: "XXXXXXXXXXXXXXXXXXXXXXXXX"
institute: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
date: "XXXXXX"
output:
beamer_presentation:
incremental: true
theme: "Berlin"
colortheme: "dove"
fonttheme: "structurebold"
includes:
in_header: preamble.tex
classoption: "aspectratio=169"
---
The `preamble.tex' file is as follows:
\usepackage{caption}
\captionsetup[figure]{labelformat=empty}
\setbeamercolor{frametitle}{fg=white,bg=black} %section slide title
\setbeamercolor{section in foot}{fg=white, bg=black} % footsections
\setbeamercolor{part title}{fg=white, bg=black}
\setbeamertemplate{footline}
{
\hbox{%
\begin{beamercolorbox}[wd=.33\paperwidth,ht=2.6ex,dp=1ex,left,leftskip=2ex]{section in foot} % footsection 1
\usebeamerfont{section in foot}\insertshortauthor
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.33\paperwidth,ht=2.6ex,dp=1ex,center]{section in foot} % footsection 2
\usebeamerfont{section in foot} \inserttitle
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.34\paperwidth,ht=2.6ex,dp=1ex,right,rightskip=2ex]{section in foot} % footsection 3
\usebeamerfont{section in foot} XXXXXXXXXXXXXXXXXXXXX
\end{beamercolorbox}}%
\vskip0pt%
}
\setbeamertemplate{section page}{
\centering
\begin{columns}
\begin{column}{\paperwidth}
\begin{beamercolorbox}[sep=12pt,center]{part title}
\usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
\end{column}
\end{columns}
}
Please don't ever use math mode for whole words, besides the missing spaces, the kerning is all messed up!
Instead you can use the \text{...} macro from the amsmath package (which is automatically loaded by beamer)
---
title: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
author: "XXXXXXXXXXXXXXXXXXXXXXXXX"
institute: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
date: "XXXXXX"
output:
beamer_presentation:
incremental: true
theme: "Berlin"
colortheme: "dove"
fonttheme: "structurebold"
includes:
in_header: preamble.tex
classoption: "aspectratio=169"
---
- $\text{Scott's pi} = \frac{\text{\% obs. agreements} - \text{\% exp. agreements}}{1 - \text{\% exp. agreements}}$
You need to use this to add space to your equations in RMarkdown: http://www.emerson.emory.edu/services/latex/latex_119.html. In your case, you just need to replace \space by \:.
Example of a .Rmd file:
---
title: "Equation with space"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
$$Scott's \: pi = \frac{\% \: obs. \: agreements - \% \: exp. \: agreements}{1 - \% \: exp. \: agreements}$$
Outuput:

How to add .sty file to rmarkdown pdf_output

I'm not sure if I have the right approach here, I've been searching all day for a way to do this, none of the documents are explicit enough in their instruction.
I would like to use a template style which looks like this:
Which I have the .sty file for. I've tried to connect that file in my rmarkdown, with a header like this:
---
title: "title"
author: "author"
date: "`r format(Sys.time(), '%d %B, %Y')`"
mainfont: Arial
output:
pdf_document:
latex_engine: xelatex
includes:
template: analysis_orax.sty
---
However, this isn't adding the style. If I add the .tex file, it adds all of the body text, which isn't what I'm going for.
I don't quite care for using .tex or .sty; all I want is to have a nicely formatted .pdf for reporting!!
The .sty:
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage[left=4cm,right=2.5cm,top=2.5cm,bottom=2cm]{geometry}
\usepackage{fancyhdr}
%------------------Main Font-------------------------
\setmainfont{Fira Sans}
%Make sure you have the compiler "XeLaTeX" activated on your settings for your LaTeX document in order to see the font
%------------------Color Set--------------------------
\definecolor{LightBlue}{RGB}{66, 163, 251}
\definecolor{DarkBlue}{RGB}{36, 100, 176}
\definecolor{LightGray}{gray}{.94}
\definecolor{DarkGray}{gray}{.172}
\definecolor{Orange}{RGB}{229, 133, 3}
\definecolor{MediumBlue}{RGB}{38, 119, 193}
%------------------Section Default Setting-------------
\titleformat*{\section}{\color{DarkBlue}\normalfont\bfseries\Huge}
\titleformat*{\subsection}{\color{LightBlue}\normalfont\bfseries\LARGE}
\titleformat*{\subsubsection}{\color{MediumBlue}\normalfont\bfseries\LARGE}
%-------------------Section Numbers Removal------------
\setcounter{secnumdepth}{0}
%-------------------------Header & Footer------------------------
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{
\begin{tikzpicture}[remember picture,overlay] \node[anchor=north west, yshift=1.5mm, xshift=-1.5mm] at (current page.north west) {\includegraphics[height=25mm]{figures/header_corner.png}};
\end{tikzpicture}
}
\fancyfoot[C]{
\begin{tikzpicture}[remember picture,overlay] \node[anchor=south east, yshift=-1.5mm, xshift=1.5mm] at (current page.south east) {\includegraphics[height=29mm]{figures/banner.png}};
\end{tikzpicture}
\textcolor{LightGray}{\thepage}
}
Though I am not sure which yaml structure you have tried, the page you might see has the right answer. However, the indentation of that answer was not correct. Just try the yaml below, in which we need to indent by two spaces to specify the arguments of output.
---
title: "title"
author: "author"
date: "`r format(Sys.time(), '%d %B, %Y')`"
mainfont: Arial
output:
pdf_document:
latex_engine: xelatex
includes:
in_header:
- analysis_orax.sty
---
The section
in_header:
- analysis_orax.sty
is equivalent to
in_header: analysis_orax.sty
in your case, but if you have more files (.sty or .tex etc.) to include in header, you can use - and line breaks to indicate the file names, as shown below.
in_header:
- analysis_orax.sty
- another_one.sty

Change the caption title of a figure in markdown

I'm currently writing a small report in German. Hence I want my figure caption titles to be changed from Figure 1 to Abbildung 1 and so on.
---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
pdf_document: default
---
```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```
Question: How can I change the default figure title (not sure if it's actually called that way) in R Markdown?
If you are writing in any language other than English, you can change the language options of the outputted pdf with the lang YAML option. This will override all the captions, labels, table of contents etc.
---
output: pdf_document
lang: de
---
```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```
Other language options include fr (French), it (Italian) etc. See http://pandoc.org/MANUAL.html#language-variables for more details.
Following the example from this question, you can define your own tex file where you can change figure caption defaults.
header.tex:
\usepackage{caption}
\captionsetup[figure]{name=Abbildung}
This is the main .Rmd file:
---
title: "Untitled"
author: "me"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
pdf_document:
includes:
in_header: header.tex
---
```{r iris, fig.cap='Iris sepal lengths'}
hist(iris$Sepal.Length)
```

unnumbered special headers in rmarkdown [duplicate]

I have an rmarkdown document (.Rmd) that I want to knit into a pdf document. number_sections has been put to 'yes' and toc to 'true'. How can I add appendix sections that appear in the table of contents but don't have a section number?
Here is an example .Rmd code. How can I let appendix A and appendix B be numberless sections and let them appear in the table of contents at the same time?
---
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
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
---
# start
# second
```{r results="asis",eval=TRUE,echo=FALSE,message=FALSE, error=FALSE, warning=FALSE, comment = NA,fig.height=4}
cat("and here some R")
```
# appendix A
# appandix B
Just add {-} after the section name. Thus, for your appendices, you should do something like:
# appendix A {-}
# appendix B {-}
For more details, see this section of the docs.
Result:

How to make part of rmarkdown document without section numbering?

I have an rmarkdown document (.Rmd) that I want to knit into a pdf document. number_sections has been put to 'yes' and toc to 'true'. How can I add appendix sections that appear in the table of contents but don't have a section number?
Here is an example .Rmd code. How can I let appendix A and appendix B be numberless sections and let them appear in the table of contents at the same time?
---
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
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
---
# start
# second
```{r results="asis",eval=TRUE,echo=FALSE,message=FALSE, error=FALSE, warning=FALSE, comment = NA,fig.height=4}
cat("and here some R")
```
# appendix A
# appandix B
Just add {-} after the section name. Thus, for your appendices, you should do something like:
# appendix A {-}
# appendix B {-}
For more details, see this section of the docs.
Result:

Resources