Automatically number sections in RMarkdown - r-markdown

I am trying to create a report in R markdown that has sections ordered
Section 1 Header
1.1 sub section 1
1.2 sub section 3
Section 2 Header
2.1
2.2 sub section
2.2.1 another sub section
Is there a way get R markdown to generate an ordered list like this?

Add the option number_sections: true to your YAML header:
---
title: "My Report"
output:
html_document:
number_sections: true
---
# Main Section
## 2nd Level
### 3rd Level
And voilá, your sections are numbered:

Related

Rmarkdown beamer slides does not show itemise bullets

I was trying to write create some beamer slides in Rmarkdown. Since the beamer slides would need to include some Chinese characters, I have to specify xelatex as the latex engine.
However, recently I found that the xelatex engine has a problem (the problem was not here a month ago): When using xelatex as the latex engine, the itemise bullets in beamer slides disappeared.
Does anyone know how to resolve this issue?
Below is a minimum working example:
---
title: trial doc
institute: |
| Department trial
| trial Education
Date: "17 October 2020"
output:
beamer_presentation:
theme: "CambridgeUS"
colortheme: "dolphin"
slide_level: 3
latex_engine: xelatex
df_print: kable
classoption: "aspectratio=169"
fontsize: 10pt
mainfont: Times New Roman
header-includes:
- \setbeamercolor{frametitle}{bg=white}
- \usepackage{ctex}
- \AtBeginSubsection{}
- \AtBeginSection{}
- \setbeamerfont{frametitle}{series=\bfseries}
- \AtBeginDocument{\title[xxx]{xxxxx}}
- \AtBeginDocument{\institute[xxxxx]{\\Department of xxx\\xxx}}
- \AtBeginDocument{\author[xxxxxx]{XXX}}
---
\frametitle{Outline}
\tableofcontents
# 欢迎
\frametitle{\textbf{Welcome}}
some text
some Chinese text 你好
trying to itemize:
- Hello
- subitem
trying some numbered list:
1. hello
2. hello
And the output I get is as below:
Output from the code above
When I try using pdflatex as the latex engine (in which case I cannot use the ctex package and cannot include Chinese characters in my beamer slides), the itemize and numbered list works perfectly.
Really appreciate if someone can help me with this!
As provided by #samcarter_is_at_topanswers.xyz above, I solved this problem by following the steps in github.com/pgf-tikz/pgf/issues/928#issuecomment-700690532.

Beamer Rmarkdown: no page number for specific slides

I have some slides produced in Rmarkdown. I just want the slides after the conclusion not to have numbers. I tried all the solutions that are posted in this website and similar (e.g.: \appendix
\setcounter{framenumber}{2}, \pagenumbering{gobble}, etc.) but they don't work. Also this Rbeamer for back-up slides doesn't work in my case and I don't understand why.
This is my framework:
---
title: "Title"
subtitle: "Subtitle"
date: "xx/xx/2020"
output:
beamer_presentation:
theme: "Boadilla"
colortheme: "orchid"
header-includes:
- \usepackage{tikz}
- \usetikzlibrary{decorations.pathreplacing,calc,tikzmark}
- \usetikzlibrary{tikzmark,fit,shapes.geometric}
- \usepackage{lipsum}
- \usepackage{lmodern}
- \usepackage{tcolorbox}
- \usepackage{appendixnumberbeamer}
---
## Title 1
Text 1
---
## Title 2
Text 2
---
## Conclusion
concluding
---
## NO PAGE NUMBER
I don't want page numbers here
Thanks a lot!

rmarkdown include TOC

I am writing rmarkdown and am exporting to odt and to html. I can get a TOC in the generated html and I can get a TOC in the generated odt, but I cannot get a TOC in both simultaneously, as the code seems mutually exclusive.
How can I have a TOC generated from the same Rmd file in both, odt and html?
Here is how I get the TOC in odt:
---
title: Test TOC
toc: yes
toc-title: TOC
output:
odt_document:
keep_md: true
html_document:
number_sections: true
---
# Just a test document
With some text
Here is how I get the TOC in html:
---
title: Test TOC
output:
odt_document:
keep_md: true
html_document:
toc: yes
toc-title: TOC
number_sections: true
---
# Just a test document
With some text
If I combine the two, I get 'yes' as TOC in html.
I am using rmarkdown 1.12 and pandoc-2.7.3
Posting a work-around here. But I am still interested in a better answer.
As a work-around I have renamed toc as odt-toc and toc-title as odt-toc-title in the odt template.
In more detail I use this Rmd file:
---
title: Test TOC
odt-toc: yes
odt-toc-title: TOC
output:
odt_document:
keep_md: true
html_document:
toc: yes
toc-title: TOC
number_sections: true
---
# Just a test document
With some text
with a modified version of the default odt-template where I have replaced
$if(toc)$
by
$if(odt-toc)$
and
<text:index-title-template text:style-name="Contents_20_Heading">$toc-title$</text:index-title-template>
by
<text:index-title-template text:style-name="Contents_20_Heading">$odt-toc-title$</text:index-title-template>

How to change the font colour used inside the chunks when building a tufte book using bookdown?

I am trying to build a book, with 9 chapters. I am using the bookdown::bookdown_site package for that, which I have included in the YAML header in index.Rmd. But when I knit the book, using bookdown::tufte_book2, the pdf file generate the text inside the chunks with different font colors.
When I try to run each chapter individually, using "tufte_handout", the outcome is as expected. Main text and inside chunk text is monochrome and TimesNewRoman.
In rStudio, before build the book, I have tried in Sweave/Program defaults to use both Latex Engines, "xeLaTex" and "pdfLaTex"
YAML header in index.Rmd
---
title: "Operations Research Using R<br />"
author: "Timothy R. Anderson"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
monofont: Times New Roman
highlight: monochrome
documentclass: book
bibliography: ["Master4Bookdowns.bib"]
---
YAML header in each individual ChapterX.Rmd file:
---
title: 'Chapter 3: More LP Models'
header-includes:
- \usepackage{longtable}
- \usepackage{caption}
monofont: Times New Roman
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
toc: TRUE
number_sections: true
highlight: monochrome
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
highlight: monochrome
---
I expect all document with the same font type and monochrome.
Since bookdown::tufte_book2 is not specified in your main YAML header, I assume you have an _output.yml file that defines the output format. In that case, you have to add highlicht: monochrome there, i.e.:
bookdown::tufte_book2:
highlight: monochrome
[other options]

Creating a footer for every page using R markdown

I'm writing a document in R Markdown and I'd like it to include a footer on every page when I knit a PDF document. Does anyone have any idea on how to do this?
Yes, this question has been asked and answered here: Adding headers and footers using Pandoc. You just need to sneak a little LaTeX into the YAML header of your markdown document.
This markdown header does the trick:
---
title: "Test"
author: "Author Name"
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---
Works for me with an Rmd file in RStudio Version 0.98.1030 for Windows.
Another option would be to use the argument includes provided by rmarkdown::pdf_document() (documentation). This allows you to keep the footer in a separate file. If your footer is defined in footer.tex, the header of your R Markdown file would look like this:
---
output:
pdf_document:
includes:
after_body: footer.tex
---
This also assumes that footer.tex is in the same directory as the R Markdown file.
Update: The file footer.tex can contain any valid LaTeX that you want to be inserted at the end of your PDF document. For example, footer.tex could contain the following:
This \textbf{text} will appear at the end of the document.
To manage the height of the footer, you can use the following:
date: '`r paste("Date:",Sys.Date())`'
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \setlength{\footskip}{-50pt} # set the footer size
Keep Coding!