How to make part of rmarkdown document without section numbering? - r

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:

Related

Using custom LaTeX class changes numbering in R Markdown

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

R Markdown: fancyhdr can't set head rule to 0 even after redefining the \headrulewidth command

I'm trying to make a quick thesis document/template, but the documents are not allowed to have a header line, just the page numbers. I can change what exists inside the header and footers (e.g. adding a page number at the top right hand of the page), but the rule won't go away.
I tried multiple variations of the following code (this being example document to try to isolate the problem):
---
title: "Test"
author: "TEst"
date: "February 14, 2018"
output: pdf_document
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \AtBeginDocument{\thispagestyle{fancy}}
- \rhead{\thepage}
- \cfoot{}
- \renewcommand{\headrulewidth}{0pt}
---
\renewcommand{\headrulewidth}{0pt}
\newpage
\renewcommand{\headrulewidth}{0pt}
# Hello
But no luck. The line is always there. I even tried the \renewcommand{\headrule}{} and it still shows up. I'm thinking this may be a pandoc error, but I'm not entirely sure. Could you guys provide some insight?
Edit: This code is now the exact test case I was using to troubleshoot. The actual document is included below as well.
---
output:
pdf_document:
fig_caption: yes
number_sections: yes
bibliography: library.bib
csl: methods-in-ecology-and-evolution.csl
urlcolor: black
linkcolor: black
fontsize: 12pt
geometry: margin = 1.2in
header-includes:
- \usepackage{placeins}
- \usepackage{fancyhdr}
- \usepackage{setspace}
- \usepackage{chngcntr}
- \usepackage{microtype}
- \onehalfspacing
- \counterwithin{figure}{section}
- \counterwithin{table}{section}
---
---
nocite: |
#Example1999, #Example2000
...
```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = 'figures/',
echo = FALSE, warning = FALSE, message = FALSE)
```
\pagenumbering{gobble}
```{r child = 'titlepage.Rmd'}
```
\newpage
```{r child = 'declaration.Rmd'}
```
\newpage
\pagestyle{fancy}
\fancyhead[LE,RO]{}
\fancyhead[LO,RE]{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\pagenumbering{roman}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[CO,CE]{Abstract}
\renewcommand{\headrulewidth}{0pt}
\section*{Abstract}
\addcontentsline{toc}{section}{Abstract}
```{r child = 'abstract.Rmd'}
```
\newpage
\fancyhead[CO,CE]{Acknowledgements}
\section*{Acknowledgements}
\addcontentsline{toc}{section}{Acknowledgements}
```{r child = 'acknowledgements.Rmd'}
```
\newpage
\fancyhead[CO,CE]{Table of Contents}
\setcounter{tocdepth}{2}
\tableofcontents
\newpage
\pagenumbering{arabic}
\newpage
\fancyhead[CO,CE]{Introduction}
```{r child = 'chapter1.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Methods}
```{r child = 'chapter2.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Results}
```{r child = 'chapter3.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{Discussion}
```{r child = 'chapter4.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{List of Figures}
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage
\fancyhead[CO,CE]{List of Tables}
\addcontentsline{toc}{section}{List of Tables}
\listoftables
\newpage
```{r child = 'appendix.Rmd'}
```
\FloatBarrier
\newpage
\fancyhead[CO,CE]{References}
# References
Edit 2: Solved it! By placing the commands into a .sty file and including that file in the header via the following
output:
pdf_document:
fig_caption: yes
number_sections: yes
includes:
in_header: test.sty
bibliography: library.bib
I have had extremely precise control over the document via the typical LaTeX syntax, so I'm making a .sty file that should hopefully let me (and others) write their dissertations in R Markdown!

How to force chapters start by uneven index page

I need my thesis chapters start by uneven index page.
My YAML header is:
---
output:
pdf_document:
number_sections: true
toc_depth: 4
fontsize: 11pt
geometry: margin=1in
header-includes:
- \usepackage[spanish]{babel}
- \usepackage{cite}
- \usepackage{xcolor}
- \definecolor{grey}{rgb}{0.9,0.9,0.9}
- \usepackage{array}
- \usepackage{multirow}
bibliography: biblio.bib
csl: biomed-central.csl
link-citations: true
---
Some LaTeX packages?
No packages, it's part of the documentclass. To do this in knitr, add these to your YAML header:
classoption: twoside
classoption: openright

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 link the contents to the actual page in Rmarkdown pdf output

I am creating several reports outputting in a pdf file via calling a markdown file from r. When a pdf file is created I would like to clink in the contents and go to the actual page.
The code that I am using at the moment is :
---
title : "My report"
author: "Myself"
output: pdf_document:
fig_caption: yes
number_section: yes
header-includes:
- \usepackage{wallpaper}
- \usepackage{\wpXoffset}{7.0cm}
- \usepackage{\wpYoffset}{12.5cm}
- \usepackage{longtable}
- \usepackage{hyperref}
---
some text
\newpage
# Introduction
\newpage
# Mytables
```{r, tables,echo = FALSE, results= "asis"}
y= 1;
for (current_table in table$tablename)
{
cat("##",current_schema);
for (current_subtable in subtable$field_name)
name_subtable = paste("###",subtable$field_name[y],"",sep = "");
cat(name_subtable,"\n","&nbsp",fill = TRUE);
y = y + 1
}
```
i.e. When I click on:
Introduction...........................................6
I would like to go at page 6.
Thanks for helping.
Try below code.
---
title : "My report"
author: "Myself"
output:
pdf_document:
fig_caption: yes
number_section: yes
toc: true
header-includes:
- \hypersetup{colorlinks=true, linkcolor=blue}
---

Resources