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
Related
My YAML header looks like this, and I would like to change only the space between the author/date, and abstract.
How can I achieve this? I have tried using \vspace{1cm} after the date (failed), and also at the start of the abstract text, but that only spaces the text, and not "Abstract" itself.
Any ideas?
---
title:
subtitle:
author: "Me "
date: "`r format(Sys.time(), '%B %d, %Y')`"
abstract: "The document shows the answer to all questions & the output (as it relates to each)"
output:
pdf_document:
keep_tex: false
toc: false
---
With an up-to-date latex installation, you can use the hook system to add a bit of space before the abstract environment or the \#date macro which inserts the date:
---
title: "test"
subtitle:
author: "Me "
date: "`r format(Sys.time(), '%B %d, %Y')`"
abstract: "The document shows the answer to all questions & the output (as it relates to each)"
output:
pdf_document:
keep_tex: false
toc: false
header-includes:
- \AddToHook{env/abstract/before}{\vspace*{4cm}}
- \makeatletter\AddToHook{cmd/#date/before}{\vspace*{4cm}}\makeatother
---
\maketitle
test
I recently discovered that you can include your own LaTeX class in an R-Markdown doc to change the appearance of the PDF. Here is a minimal example:
R Markdown
---
title: "Test"
date: "`r format(Sys.time(), '%d %B, %Y')`"
documentclass: book
output:
pdf_document:
citation_package: natbib
toc: yes
toc_depth: 3
number_sections: true
fontsize: 12pt
---
# A
## AA
### AAA
### AAA
## AB
# B
This works as intended.
But when I define my own class, the numbering is preceded by 0s and the page numbering is off.
myclass.cls
I place a file called "myclass.cls" in the same direcoty as the RMD file above and change documentclass: myclass:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{glasgowthesis}
\LoadClass{book}
My understanding is that this should simply call the same class as above but the file now looks like this:
Maybe somebody can give me a hint what I'm doing wrong. I would like to copy the book class 1:1 before starting to change things.
I found the solution in the bookdown book and wanted to share it in case anyone wanders off to this question through google etc.
Note that when you change documentclass, you are likely to specify an
additional Pandoc argument --top-level-division=chapter so that Pandoc
knows the first-level headers should be treated as chapters instead of
sections (this is the default when documentclass is book)
So this YAML header solved the issue:
---
title: "Test"
date: "`r format(Sys.time(), '%d %B, %Y')`"
documentclass: myclass
output:
pdf_document:
pandoc_args: --top-level-division=chapter
citation_package: natbib
toc: yes
toc_depth: 3
number_sections: true
fontsize: 12pt
---
# A
## AA
### AAA
### AAA
## AB
# B
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)
```
In RMarkdown, I seem to be able to create 'some' dynamic variables in the YAML header, but not for others:
For instance, this works:
---
title:
"Some Title, `r format(Sys.time(), '%d %B, %Y')`"
...
---
But this does NOT.
---
...
pdf_document:
keep_tex: `r 'true'`
---
But this DOES (ie not dynamic).
---
...
pdf_document:
keep_tex: true
---
So how can I 'dynamically' assign the keep_tex to either true or false, what I want to do, is something like this:
---
...
pdf_document:
keep_tex: `r getOption('mypackage.keep_tex')`
---
I don't know if the template options can be set programmatically in the YAML header of the .Rmd file.
As an alternative, if you use rmarkdown::render to render your document, you may specify the output template (pdf_document), and then set template options (e.g. keep_tex) programmatically.
For example, if you have a .Rmd file called "test.Rmd" like this:
---
title:
"Some Title, `r format(Sys.time(), '%d %B, %Y')`"
---
...and some logical object which determines whether to keep the intermediate TeX file or not, e.g.
my_keep <- TRUE
...you may render the input file to PDF format and keep the TeX file like this:
render(input = "test.Rmd",
output_format = pdf_document(keep_tex = my_keep))
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.