Some help to write a doctoral thesis with R Markdown - r-markdown

I'm trying to figure out how I could write my doctoral thesis using R Markdown. Usually, I write articles with Latex. But, I'd like to be able to compile my file both for Word and pdf. Could you please help me understand how I could achieve that? I need to number the \frontmatter in roman numbers and the \mainmatter in arabic numbers.
This is my MWE:
---
title: "A title"
documentclass: book
classoption:
- hidelinks
- twoside
- openright
papersize: a4paper
output:
pdf_document:
includes:
in_header: Mypreamble.tex
latex_engine: xelatex
citation_package: biblatex
toc: yes
toc_depth: 4
number_sections: yes
html_document:
toc: yes
toc_depth: '4'
df_print: paged
word_document:
toc: yes
toc_depth: 4
date: "8 juillet 2022"
bibliography: Lectures.bib
fontsize: 12pt
geometry: left=4cm,right=4cm,top=4cm,bottom=4cm
linestretch: 1.2
toc-title: Plan
links-as-notes: yes
link-citations: yes
header-includes:
- \usepackage{fontspec}
- \setmainfont[Mapping=tex-text]{Arial}
- \usepackage [french]{babel}
- \usepackage[backend=biber,style=apa]{biblatex}
---
Introduction

I did my PhD thesis entirely in R Markdown, outputting to Microsoft Word.
I have a Github repository here if it helps: https://github.com/dannyjnwong/PhD_Thesis
I have also previously blogged about the process here:
https://dannyjnwong.github.io/Writing-a-multi-chapter-document-with-R-Markdown/

Related

How to have roboto font in bookdown::pdf_document2?

Anyone suggestions on how to get roboto font in bookdown::pdf_document2?
The code below works fine, when I change the font to Roboto it does not, see also picture. The Roboto and the Comic Sans MS font are in my c:\Windows\Fonts, I use Miktex for pdf-ing. Thanks!
---
header-includes:
- \usepackage{fontspec}
- \setmainfont{Comic Sans MS}
output:
bookdown::pdf_document2:
toc: false
latex_engine: xelatex
---
# Title
This is some text.
This is some more text.
You can do \usepackage{roboto}. See README of the package for further detailed usage. If you knit the document without roboto package, programmes for knitting documents using LaTeX (e.g. R's tinytex or even MikTeX) will automatically install the missing package(s). See the relevant page of R Markdown Cookbook.
To make specific texts san serif
---
header-includes:
- \usepackage{roboto}
# - \usepackage[sfdefault]{roboto} # To make every texts san serif
output:
bookdown::pdf_document2:
toc: false
latex_engine: xelatex
---
# Title
This is some text.
This is some more text.
`\textsf{This is a san serif text.}`{=latex}
To make every texts san serif
---
header-includes:
#- \usepackage{roboto}
- \usepackage[sfdefault]{roboto} # To make every texts san serif
output:
bookdown::pdf_document2:
toc: false
latex_engine: xelatex
---
# Title
This is some text.
This is some more text.
`\textsf{This is a san serif text.}`{=latex}

How to reduce space between title and content in pdf_output of Rmarkdown

I am using Rmarkdown to output pdf file. Here is the code:
---
title: |
| This is title
|
| \vspace{-5truemm}Supplementary Material\vspace{-5truemm}
author: 'xxx^[Correspondence to: xxx. Email: xxx]'
geometry: margin=0.3in
fontfamily: mathpazo
fontsize: 11pt
documentclass: article
urlcolor: blue
output:
pdf_document:
toc: true
toc_depth: 4
number_sections: yes
subparagraph: yes
header-includes: |
\usepackage{titlesec}
\titlespacing{\title}{0pt}{\parskip}{-\parskip}
---
\vspace{-5truemm}
# Introduction
This is introduction...
# Installation
This is installation...
## test1
### subtest1
And I want to know how to reduce space between the title (Supplementary Material) and content (not the body because I set toc as true).
Many thanks advanced!
As described in TeXSO, you can use the following package:
\usepackage{tocloft}
\setlength{\cftbeforetoctitleskip}{-\baselineskip}
So, the complete example would be like this.
---
title: |
| This is title
|
| \vspace{-5truemm}Supplementary Material\vspace{-5truemm}
author: 'xxx^[Correspondence to: xxx. Email: xxx]'
geometry: margin=0.3in
fontfamily: mathpazo
fontsize: 11pt
documentclass: article
urlcolor: blue
output:
pdf_document:
toc: true
toc_depth: 4
number_sections: yes
subparagraph: yes
header-includes: |
\usepackage{titlesec}
\titlespacing{\title}{0pt}{\parskip}{-\parskip}
\usepackage{tocloft}
\setlength{\cftbeforetoctitleskip}{-\baselineskip}
---
<!--
The following \vspace{} changes the spacing
between the first section ("Introduction" here)
and the last line of the title ("Supplementary Material")
-->
\vspace{-5truemm}
# Introduction
This is introduction...
# Installation
This is installation...
## test1
### subtest1
Note that the \vspace{} before the # Introduction changes the spacing
between the first section (Introduction here)
and the last line of the title (Supplementary Material).
Thus, the \vspace{} has nothing to do with
the space between the title and TOC.

How can i indent the first line only of a paragraph in R markdown?

I am writing my thesis in R Markdown and knitting either an an HTML or word document and i want to indent only the first line in each paragraph. Is there a way to do it?
I've tried 'indent' true' in the YAML but it did not work
here is the YAML header:
bibliography: references.bib
output:
html_document:
code_folding: show
toc: true
theme: journal
fig_caption: true
df_print: paged
number_sections: true
indent: true
word_document:
toc: true
indent: true
link-citations: true
csl: nature.csl
biblio-style: nature

twin column article in bookdown

I am using bookdown::pdf_document2 and I would like to create an article with 2 columns. I am using bookdown to be able to do section referencing.
I used pandoc_args: [
"-V", "classoption=twocolumn" but that made it ignore the font and default to computer modern. Is there a way to get 2 columns articles with pdf_document2 ?
I am using the following header:
output:
bookdown::pdf_document2:
fig_crop: no
keep_tex: yes
latex_engine: xelatex
number_sections: yes
toc: yes
toc_depth: 5
fontsize: 12pt
editor_options:
chunk_output_type: console
sansfont: Source Sans Pro
mainfont: Source Sans Pro
mathfont: Calibri
You can set the classoption within the YAML header:
---
output:
bookdown::pdf_document2:
fig_crop: no
keep_tex: yes
latex_engine: xelatex
number_sections: yes
toc: yes
toc_depth: 5
fontsize: 12pt
editor_options:
chunk_output_type: console
sansfont: Liberation Sans
mainfont: Liberation Sans
classoption: twocolumn
---
I changed the font to one that's available on my system.

How to I vertically center the title of my rmarkdown pdf document?

I have the following preamble:
---
title: "Luke Klein Dissertation MARKDOWN ROUGH DRAFT"
author: "Luke KLEIN"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: true
---
How do I get my title centered on the cover page?
You probably already finished your dissertation :-) but leaving the solution for future reference as i came here through google.
---
title: |
| \vspace{5cm} \LARGE{Luke Klein Dissertation MARKDOWN ROUGH DRAFT}
author: "Luke KLEIN"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: true
---
Using a combination of vspace and hspace you can put the title anywhere you want.
Other combinations of fonts (both size and type) can be seen here:
https://www.sharelatex.com/learn/Font_sizes,_families,_and_styles?nocdn=true
Late to the party, this worked for me :
---
title: "Luke Klein Dissertation MARKDOWN ROUGH DRAFT"
author: "Luke KLEIN"
date: "`r Sys.Date()`"
output:
pdf_document:
toc: true
header-includes:
- \pretitle{\begin{center} \vspace{5cm}}
---