Skip to content

Commit

Permalink
Merge branch 'master' into project-restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Harper committed Dec 9, 2018
2 parents ec067a3 + 2558acd commit 2131b16
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 7 deletions.
Binary file removed .DS_Store
Binary file not shown.
48 changes: 43 additions & 5 deletions book/04-latex/latex-header-footer.Rmd
Expand Up @@ -4,7 +4,7 @@

We can use LaTeX package **fancyhdr** to customise the header and footer of PDF outputs. It provides several commands that allow you to customize the header and footer lines of your document. For a more complete guide, please refer to the [full documentation](http://tug.ctan.org/tex-archive/macros/latex/contrib/fancyhdr/fancyhdr.pdf). To begin with, we must load the package and change the header style:

```
```latex
\usepackage{fancyhdr}
\pagestyle{fancy}
```
Expand All @@ -26,14 +26,40 @@ For example, `\fancyhead[LE,RO]{Your Name}` will print the text "Your Name" on t
- `\leftmark`: adds name and number of the current top-level structure in uppercase letters.
- `\rightmark`: adds name and number of the current next to top-level structure in uppercase letters.

Piecing this components together, a complete example is presented below. The code has been included directly within the YAML:

Piecing this components together, a complete example is presented below.

This could be inserted in the document, or another `header.tex` file :

```latex
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[CO,CE]{Your Document Header}
\fancyfoot[CO,CE]{And this is a fancy footer}
\fancyfoot[LE,RO]{\thepage}
```

If in an external `.tex` file, then it could be included in the header of our `rmarkdown::pdf_document` format:

```{yaml, eval = FALSE}
title: "Document with header and footer"
output:
pdf_document:
includes:
in_header: header.tex
---
```

The `includes` feature of `pdf_document` is presented in [Advanced customisation](https://bookdown.org/yihui/rmarkdown/pdf-document.html#includes-1) of @xie2018.

An alternative,^[You cannot use both as `in_header:` in yaml will currently override the content of pandoc variable `header-includes`] it could also be included directly in header to a rmarkdown document within the YAML using the pandoc variable `header-includes`:

```yaml
---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{YOur Document Header}
- \fancyhead[CO,CE]{Your Document Header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
Expand All @@ -43,7 +69,19 @@ output: pdf_document
### Force Header and footer for every page
<!--- https://stackoverflow.com/questions/30922602/creating-a-footer-for-every-page-including-first-using-r-markdown --->

By default, headers and footers will not be displayed on the first page of your PDF document. If we wish to show our footer on the front page, we must include an additional line in the YAML frontmatter specification `\fancypagestyle{plain}{\pagestyle{fancy}}`.

By default, headers and footers will not be displayed on the first page of your PDF document. If we wish to show our footer on the front page, we must include an additional line `\fancypagestyle{plain}{\pagestyle{fancy}}`.

As an example in the YAML frontmatter specification

```yaml
---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{YOur Document Header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
- \fancypagestyle{plain}{\pagestyle{fancy}}
output: pdf_document
---
```
51 changes: 51 additions & 0 deletions book/09-workflow/rstudio-integration.Rmd
@@ -0,0 +1,51 @@
## RStudio integration with R Markdown

R Markdown format and features can be used with R and **rmarkdown** package, with any editor that got your preference. However, RStudio has a deep integration with R Markdown and offers additional feature that will help your project workflow without a doubt.

### R Markdown specific Rstudio keyboard shorcuts

<!--- https://stackoverflow.com/questions/30938280/keyboard-shortcut-to-produce-code-chunk-brackets-in-markdown-in-r-for-rstudio --->

Like any great IDE, RStudio has keyboard shorcuts ^[A full list can be found on the [web](https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts) or directly in the IDE under tools menu `Tools -> Keyboard Shortcuts Help.`] and some are specific to R Markdown. Some of the most useful shortcuts are summarised in Table \@ref(tab:keyboardShortcuts).

```{r, include = FALSE}
ks_win <- function(letters, ctrl = TRUE, alt = TRUE, shift = FALSE, enter = FALSE) {
paste0(
if (ctrl) "Ctrl+",
if (alt) "Alt+",
if (shift) "Shift+",
if (enter) "Enter+",
letters
)
}
ks_mac <- function(letters, cmd = TRUE, opt = TRUE, shift = FALSE, enter = FALSE) {
paste0(
if (cmd) "Command+",
if (opt) "Option+",
if (shift) "Shift+",
if (enter) "Enter+",
letters
)
}
```

```{r keyboardShortcuts, echo = FALSE}
keyboard_table <- tibble::tribble(
~ "Description" , ~ "Windows & Linux" , ~ "Mac",
"Insert R chunk" , ks_win("I") , ks_mac("I"),
"Preview HTML" , ks_win("K", alt = FALSE, shift = TRUE) , ks_mac("K", opt = FALSE, shift = TRUE),
"Knitr document (knitr)" , ks_win("K", alt = FALSE, shift = TRUE) , ks_mac("K", opt = FALSE, shift = TRUE),
"Compile Notebook" , ks_win("K", alt = FALSE, shift = TRUE) , ks_mac("K", opt = FALSE, shift = TRUE),
"Compile PDF" , ks_win("K", alt = FALSE, shift = TRUE) , ks_mac("K", opt = FALSE, shift = TRUE),
"Run all chunks above" , ks_win("P") , ks_mac("P"),
"Run current chunk" , ks_win("C") , ks_mac("C"),
"Run current chunk" , ks_win("Enter", TRUE, FALSE, TRUE) , ks_mac("Enter", TRUE, FALSE, TRUE),
"Run next chunk" , ks_win("N") , ks_mac("N"),
"Run all chunks" , ks_win("R") , ks_mac("R"),
"Go to next chunk/title" , ks_win("PgDown", alt = FALSE) , ks_mac("PgDown", opt = FALSE),
"Go to previous chunk/title", ks_win("PgUp", alt = FALSE) , ks_mac("PgUp", opt = FALSE),
"Show/hide document outline", ks_win("O", TRUE, FALSE, TRUE) , ks_mac("O", TRUE, FALSE, TRUE),
"Build book, website, ..." , ks_win("B", TRUE, FALSE, TRUE) , ks_mac("B", TRUE, FALSE, TRUE)
)
knitr::kable(keyboard_table, caption = "Rmarkdown related Rstudio keyboard shorcuts")
```
Binary file modified book/images/latexLogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions examples/latex-logo/latex-logo.Rmd
@@ -1,7 +1,6 @@
---
title: "Adding a Logo to LaTeX Title"
author: Michael Harper
subtitle: Easy tips to style your PDF output
date: 7th December 2018
output: pdf_document
header-includes:
Expand All @@ -13,4 +12,4 @@ header-includes:
<!--- Optionally include a page break. This will force the start of the document to the second page --->
\newpage

This is your report.
This is your report.

0 comments on commit 2131b16

Please sign in to comment.