My little rmarkdown example is as follows:
---
# documentclass: article
output:
pdf_document:
latex_engine: xelatex
# linestretch: 1.5
fontsize: 18pt # 10pt
header-includes:
- \usepackage{lipsum}
- \usepackage{setspace}\doublespacing #\singlespacing
- \usepackage[shortlabels]{enumitem}
- \setlist{nosep}
- \setlist{noitemsep}
- \setcounter{enumi}{-1}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## random
\lipsum
## R Markdown
itemize itemize itemize itemize itemize itemize itemize itemize itemize
- aaa
- bbb
- ccc
enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate
1. uuu
1. vvv
1. www
why why why why why why why why why why why why why why why why why why why why why
I have two issues: changing fontsize from 10pt to 18pt is not working; commenting \setlist{nosep}, \setlist{noitemsep} and \setcounter{enumi}{-1} or not makes no difference. Why these happen since this example is quite simple? (ps: setspace works well)
18pt is not an allowed class option. With the default article class only a handful of normal sizes are defined. You can extent this by switching to the extarticle class which has the 17pt option:
---
documentclass: extarticle
output:
pdf_document:
latex_engine: xelatex
# linestretch: 1.5
fontsize: 17pt # 10pt
header-includes:
- \usepackage{lipsum}
- \usepackage{setspace}\doublespacing #\singlespacing
- \usepackage[shortlabels]{enumitem}
- \setlist{nosep}
- \setlist{noitemsep}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## random
\lipsum
## R Markdown
itemize itemize itemize itemize itemize itemize itemize itemize itemize
- aaa
- bbb
- ccc
enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate enumerate
1. uuu
1. vvv
1. www
why why why why why why why why why why why why why why why why why why why why why
Related
I am trying to use Rmarkdown to create answer/solutions twin PDF documents. I embedded the solutions in a frame using the tcolorbox LaTeX package. Also, I am using LaTeX's comment package to easily toggle the solutions on and off. However, R chunks inside the comment environment are not well rendered. Here's a MWE:
---
title: "Untitled"
output:
pdf_document
header-includes:
- \usepackage{tcolorbox}
- \usepackage{comment}
- \includecomment{comment} % toggle include / exclude
- \newcommand{\benum}{\begin{enumerate}}
- \newcommand{\eenum}{\end{enumerate}}
---
```{r, include=FALSE}
library(tidyverse)
```
\benum
\item The R chunk inside the \verb+comment+ environment is not rendered correctly:
\begin{comment}
\tcolorbo
```{r, echo=TRUE, eval = TRUE, results='asis'}
a <- rnorm(20)
a
```
\endtcolorbox
\end{comment}
\item But the same chunk outside the \verb+comment+ environment is rendered fine:
\tcolorbox
```{r, echo=TRUE, eval = TRUE, results='asis'}
a <- rnorm(20)
a
```
\endtcolorbox
\eenum
Here's the result:
How can I achieve what I want?
Many thanks in advance!
I am creating a RMarkdown template of Beamer slides and use the metropolis theme as a basis.
Now I want to add a footer with some text on the left side and the slide number as fraction on the right side. That works. Furthermore, the whole footer should not be shown on the title & content page. How can I control where the foot line is shown?
This is my (minimal working example):
slides.rmd
---
title: "Title"
subtitle: "Subtitle"
author: "Simon"
institute: "RUB"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: no
latex_engine: xelatex
#theme: metropolis
includes:
in_header:
#- toc.tex
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{\tiny{\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021}}}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Level I
Test
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
I know that it would be possible in Latex via the begingroup & endgroup command combined with the plain-option ({}) used on \setbeamertemplate{footline}:
\documentclass{beamer}
\setbeamertemplate{footline}[frame number]
\begin{document}
\begin{frame}
normal frame
\end{frame}
\begingroup
\setbeamertemplate{footline}{}
\begin{frame}
without footline
\end{frame}
\endgroup
\begin{frame}
normal frame
\end{frame}
\end{document}
But I don't know how to implement it in RMarkdown.
To remove the footline from your title and toc page, you can use the same trick as in https://topanswers.xyz/tex?q=1004#a1198
Add the following to your header includes:
\makeatletter
\def\ps#navigation#titlepage{%
\setbeamertemplate{footline}{}
\#nameuse{ps#navigation}
}
\addtobeamertemplate{title page}{\thispagestyle{navigation#titlepage}}{}
\pretocmd{\tableofcontents}{\thispagestyle{navigation#titlepage}}{}{}
\makeatother
(please also note that the syntax \tiny{...} is wrong. This macro is a switch and does not take an argument. You can instead use {\tiny ...}
---
title: "Title"
subtitle: "Subtitle"
author: "Simon"
institute: "RUB"
date: "September 22, 2021"
output:
beamer_presentation:
keep_md: true
keep_tex: no
latex_engine: xelatex
#theme: metropolis
includes:
in_header:
#- toc.tex
slide_level: 2 # which header level should be printed as slides
incremental: no
header-includes:
- \usetheme[numbering=fraction]{metropolis}
- \definecolor{beaublue}{rgb}{0.74, 0.83, 0.9}
- \setbeamertemplate{frame footer}{{\tiny\textcolor{beaublue}{Conference 56. Jahrestagung der DGSMP, 2021}}}
- \makeatletter
- \def\ps#navigation#titlepage{\setbeamertemplate{footline}{}\#nameuse{ps#navigation}}
- \addtobeamertemplate{title page}{\thispagestyle{navigation#titlepage}}{}
- \pretocmd{\tableofcontents}{\thispagestyle{navigation#titlepage}}{}{}
- \setbeamertemplate{section in toc}{\leavevmode\inserttocsectionnumber. \inserttocsection\par}
- \makeatother
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Content
\tableofcontents[]
# Level I
Test
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
# Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
A question about fancyhdr in R Markdown knitting to pdf.
Can anyone help me to fix the header for the appendix? I have numbered sections in the document, and the fancyhead for pages with the numbered sections is oke. But for the unnumbered appendix, it keeps showing the last numbered section, where I just want the title of the current unnumbered appendix to be shown. Code example below. Thanks!
---
title: "Example"
output:
pdf_document:
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
---
\newpage
# Chapter
\newpage
# Appendix {-}
You can adjust the header like this:
---
title: "Example"
output:
pdf_document:
number_sections: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
---
\newpage
# Chapter
\newpage
# Appendix {-}
\markboth{something here}{something there}
I'm building a presentation using rmarkdown and LaTeX/Beamer. I would like to reduce the spacing between the displayed R-commands and R-output. I believe this is related to the paragraph spacing options in LaTeX/Beamer.
Is this something I should do in rmarkdown (chunk options, knit_hooks, or something else?), in the pandoc Yaml header (some pandoc option?), or in the LaTeX beamer template file? I feel like it should be in the LaTeX template file.
Below is a working example of a minimal markdown file, and a .tex template file I'm using to control some beamer settings.
example.Rmd
---
title: "Untitled"
author: "Ryan"
date: "March 1, 2016"
output:
beamer_presentation:
pandoc_args: '--latex-engine=xelatex'
includes:
in_header: latex-topmatter.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Vertical Spacing is too much
Here is a working example.
- some
- bullets
Example code:
```{r, echo = TRUE}
a <- 1
a
a+a
```
latex-topmatter.tex
% declare overall beamer theme to use as baseline
\usetheme{default}
% make code-output smaller
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{fontsize=\tiny,commandchars=\\\{\}}
% make console-output smaller:
\makeatletter
\def\verbatim{\tiny\#verbatim \frenchspacing\#vobeyspaces \#xverbatim}
\makeatother
% set vertical spacing between paragraphs:
% \parskip{0pt}
% \addtobeamertemplate{blocks}{}{\setlength{\parskip}{0pt}}
% \addtobeamertemplate{block begin}{}{\setlength{\parskip}{0pt}}
% \addtobeamertemplate{block end}{}{\setlength{\parskip}{0pt}}
% % \setlength{\emergencystretch}{0em}
\setlength{\parskip}{0pt}
I've tried making the font of the R-commands or R-output smaller, which does not seem to affect the paragraph spacing.
I've tried using knit_hooks() as in this example:
https://github.com/ramnathv/slidify/issues/189, which mostly works - but then i can't seem to reduce the fontsize of the code and output.
I've also tried using \parskip{0pt}, and several other beamer options or parskip options, which are commented in the above latex-topmatter.tex section. None of them seem to change the spacing between chunks of text, R-code, or R-output. Am I even looking in the right place?
Here is a working example. Notice the definitions at the end of the header file:
Source code chunks are contained inside a Shaded environment which in turn uses \OuterFrameSep for its spacing. So we need to redefine that.
With \preto we prepend the commands \topsep=-10pt \partopsep=-10pt to every verbatim environment. This affects the spacing of output chunks.
example.Rmd
---
title: "Untitled"
author: "Martin"
date: "January 4, 2017"
output:
beamer_presentation:
keep_tex: yes
pandoc_args: --latex-engine=xelatex
includes:
in_header: latex-topmatter.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Vertical Spacing is just right
Here is a working example.
- some
- bullets
Example code:
```{r, echo = TRUE}
a <- 1
a
a+a
```
latex_topmatter.tex
% declare overall beamer theme to use as baseline
\usetheme{default}
% make code-output smaller
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{fontsize=\tiny,commandchars=\\\{\}}
% make console-output smaller:
\makeatletter
\def\verbatim{\tiny\#verbatim \frenchspacing\#vobeyspaces \#xverbatim}
\makeatother
\setlength{\parskip}{0pt}
\setlength{\OuterFrameSep}{-4pt}
\makeatletter
\preto{\#verbatim}{\topsep=-10pt \partopsep=-10pt }
\makeatother
Why does the following R Markdown minimal (non)-working example not compile to PDF?
---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{The performance of new graduates}
- \lfoot{From: K. Grant}
- \cfoot{To: Dean A. Smith}
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
---
# Test
In particular, the problematic conversion happens to -\lfoot{From: K. Grant} and -\cfoot{To: Dean A. Smith}, as seen in the output .tex file:
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{The performance of new graduates}
true
true
For some reason, both of these lines are converted to true causing
LaTeX error: Missing \begin{document}
thereby preventing the document from compiling to PDF.
Changing \lfoot and \cfoot to just about anything else seems to lead to them being converted correctly. So what's going on here? I take it that there must be a problem with either knitr or pandoc in the conversion process.
NB: I'm not too familiar with R Markdown, and this is a follow-up question to Headers and footers created in Fancyhead not shown in PDF on TeX.SX on Tom's behalf.
The : character is the problem. pandoc seems to be trying to parse the header-includes content as if it were variables, and : is used to separate variables and values. It compiles if you quote the lines in question (don't forget, then, to escape the leading backslash)
---
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \lhead{}
- \chead{}
- \rhead{The performance of new graduates}
- "\\lfoot{From: K. Grant}"
- "\\cfoot{To: Dean A. Smith}"
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
---
# Test
Stitching the answer here with trial and error, I found that only by deleting the title key and using YAML pipe-denoted multiline string syntax would it compile:
---
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
header-includes: |
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\lhead{My Title}
\rhead{My Note}
\lfoot{\today}\rfoot{Page \thepage}
---
I recommend using pandoc's raw_attribute feature (enabled by default) to mark the raw LaTeX section as such. This is the most robust solution.
header-includes: |
```{=latex}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\lhead{My Title}
\rhead{My Note}
\lfoot{\today}\rfoot{Page \thepage}
```