Chapter 8 R Markdown

8.1 YAML

title: "TITLE"
author: "AUTHOR"
date: "`r format(Sys.time(), '%d %B, %Y')`" # current date
header-includes:
  - \usepackage{xcolor} # allows to add color to text
  - \usepackage{fancyhdr} # define footer and header (package)
  - \pagestyle{fancy}
  - \fancyhead[C]{SPGRow Individual Report}
  - \fancyfoot[R]{Ana Maria Esteves} # PARTICIPANT NAME
  - \fancyfoot[C]{\thepage}
# logo in the bottom left (can take any format, .png, .jpg, and .pdf)
  - \fancyfoot[L]{\includegraphics[width = .2\textwidth]{LOGO.png}} 
  - \usepackage[default]{sourcesanspro} # define font (package; step 1/2)
  - \usepackage[T1]{fontenc}
# logo in the 1st page
  - \usepackage{titling} 
  - \pretitle{\begin{center}
  \LARGE\includegraphics[width=5cm]{LOGO.png}\\[\bigskipamount]}
  - \posttitle{\end{center}}
# prevent figures from floating
  - \usepackage{float} 
  - \floatplacement{figure}{H}
mainfont: SourceSansPro # define font (step 2/2)
output:
  pdf_document:
  includes:
    in_header: header.tex # allows page break code
  number_sections: yes # numbers sections, use {-} to pass
toc: yes # tables of contents
toc_depth: 4
toc-title: Contents
lot: FALSE # list of tables

8.2 Text Formatting

8.2.1 text color and highlight

Examples:
- \colorbox{red}{highlight in red} for
- \colorbox[rgb]{1,0.71,0.71}{highlight in rgb defined color} for
- \textcolor{red}{text in red} for
- \textcolor[rgb]{1,0.71,0.71}{text in rgb defined color} for

8.3 In Line Coding

  • requires header.tex file
  • \newpage for a page break
  • \hfill\break for a line break
  • \newpage and \blandscape starts landscape, \elandscape and \newpage ends landscape

8.4 Knirt

  • to create tables to be printed:
knitr::
  kable(DF, longtable = T, booktabs = T, caption = "CAPTION", 
    linesep = "\\addlinespace", digits = 2, col.names = NULL) %>% 
  kable_styling(latex_options = c("repeat_header", "striped"), # for some reason "striped" does not work with `full_width = T` 
      font_size = 10, full_width = T) %>%
  column_spec(1, width = "25em") %>% 
  footnote(general = "FOOTNOTE)