I wrote my own titlepage and it is loaded via an include in the R-markdown file. However, this conflicts with the pandoc title. I am trying to find settings in the R markdown yaml header such that pandoc does not insert the following code snipped into the tex-file.
% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
\posttitle{
\begin{center}\large#1\end{center}
}
}
\setlength{\droptitle}{-2em}
\title{}
\pretitle{\vspace{\droptitle}}
\posttitle{}
\author{}
\preauthor{}\postauthor{}
\date{}
\predate{}\postdate{}
There is no clear indication in the pandoc documents or the r markdown guidelines how to disable the title generation. Any help would be appreciated.
Update: In particular, I am looking for solutions that allow me to keep creating my title page with the \maketitle command. That is why I focussed on this particular code snipped that I want to get rid of.
I also use my own title page with rmarkdown documents for latex/pdf outputs. To remove the title, you can add the following command in a text file called with in_header :
\AtBeginDocument{\let\maketitle\relax}
A reproductible example with the header.tex file built directly within the Rmd document:
---
title: "RMarkdown No title Test"
author: "StatnMap"
date: "July 30, 2017"
output:
pdf_document:
includes:
in_header: header.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r rm_title_page, echo=FALSE}
head <- cat('
\\AtBeginDocument{\\let\\maketitle\\relax}
', file = "header.tex")
```
# Title 1
**Some text**
# Title 2
**Some text**
Using compact-title: false in the YAML works.
---
title: "This title is not compact"
author: "Test"
date: "2019 May 10"
output: pdf_document
compact-title: false
---
I had the same problem today. Here's what I did. (Maybe I'll update the solution when I come up with something better.)
The solution is dumb but useful. I can't set an arbitrary space between the lines now, because I used \newline.
---
title: "\\huge My Smart Title"
author: "\\newline \\Large My Smart Author"
date: "\\newline \\Large 2018-12-25"
output:
pdf_document:
includes:
in_header: preamble.tex
latex_engine: xelatex
---
Below are the outputs before and after the solution.
BEFORE:
AFTER:
Note:
You may be confused about the different sizes of the "author" and the "date" in the two pictures above, if you don't know that the fontsize of the "author" and the "date" is \large instead of \Large by default.
END
Related
I'm using R markdown to make a beamer presentation.
When I try to include an error message output from R on the slide it goes off the page.
Here is my code:
---
title: "Untitled"
author: "John Smith"
date: '2022-04-29'
output: beamer_presentation
---
This error message goes off the page
```{r cars, echo = TRUE, error=TRUE}
summary(carrrrrrrrrrrrrrrrs)
```
And, this is what the slides look like:
How do I keep the code on the page, either by putting it on multiple lines or reducing font size?
You can use the same technique as in Change representation (background-color & frame) of chunks in RMarkdown (with Beamer-Presentations) to redefine the verbatim environment in such a way that it uses the listings package. The listings package then allows you to both add line breaks and adjust the font size to your liking:
---
title: "Untitled"
author: "John Smith"
date: '2022-04-29'
output:
beamer_presentation:
keep_tex: true
header-includes:
- \let\verbatim\undefined
- \let\verbatimend\undefined
- \usepackage{listings}
- \lstnewenvironment{verbatim}{\lstset{breaklines=true,basicstyle=\ttfamily\footnotesize}}{}
---
This error message goes off the page
```{r cars, echo = TRUE, error=TRUE}
summary(carrrrrrrrrrrrrrrrs)
```
Can anyone help me understand how to write my header so that the figure caption and cross reference works?
I am practicing making captions and cross references to a simple plot in my Rmd file. I understand that to do so, I should add to my header: "output: bookend::pdf_document2" and "fig_caption = yes". Then, to a chunk called myfigure, I should add "fig.cap = "\label{fig:myfigure} My caption". To cross reference this figure I should write in the text "#ref(fig:myfigure)". My code is below. It won't knit because the formatting of the header is wrong.
---
title: "knit"
author: "Chase Hommeyer"
date: "4/1/2019"
output: bookdown::pdf_document2
toc: true
fig_caption: yes
---
```{r myfigure, fig.cap = "\\label{fig:myfigure} My caption"}
plot(pressure)
```
My plot is called \#ref(fig:myfigure).
Then, I tried deleting the whitespace before toc and fig_caption, and it knit, but no caption appeared, and the text literally printed "#ref(fig:myfigure)" instead of a cross reference. The header I tried is here:
---
title: "knit"
author: "Chase Hommeyer"
date: "4/1/2019"
output: bookdown::pdf_document2
toc: true
fig_caption: yes
---
I also tried adding "pdf_document:" to the header, but the same issue of no caption and the cross reference being literally "#ref(fig:myfigure)". This header I tried is here:
---
title: "knit"
author: "Chase Hommeyer"
date: "4/1/2019"
output: bookdown::pdf_document2
pdf_document:
toc: true
fig_caption: yes
---
Can anyone help me understand how to write my header so that it works?
use \ref{fig:myfigure} instead of \\#ref(fig:myfigure)
See RStudio Community Post
You have a wrong YAML header and some wrong understanding of referencing. I used this RMD file:
---
title: "knit"
author: "Chase Hommeyer"
date: "4/1/2019"
output:
bookdown::pdf_document2:
toc: true
fig_caption: yes
---
```{r myfigure, fig.cap = "My caption"}
plot(pressure)
```
My plot is called Figure \#ref(fig:myfigure).
First, break the line after output in the header. The whitespaces are very important in the YAML header!
Then, read the bookdown manual:
The label of a figure environment is generated from the label of the code chunk, e.g., if the chunk label is foo, the figure label will be fig:foo (the prefix fig: is added before foo). To reference a figure, use the syntax, where label is the figure label, e.g., fig:foo.
To reference your plot with the chunk name "myfigure", just write \#ref(fig:myfigure). The caption of the figure can be set via fig.cap in the chunk options.
The following header is from a R Markdown document which I have compiled as a PDF. It results in code snippets being cropped. Commenting out the PDF output block and uncommenting the HTML block results in well-formatted HTML output.
Is there a parameter I can change to fix this? Or do I need to format my code snippets differently?
---
title: "fmodbc Package"
author: "Bobby Rohrkemper, Software Developer at Schweiz Tourismus"
date: "`r Sys.Date()`"
# output:
# rmarkdown::html_vignette:
# toc: TRUE
output:
pdf_document:
toc: TRUE
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Or should I perhaps try a different theme? I would be interested in the Tufte Handout theme, but thought it makes more sense to fix the standard output first.
http://rmarkdown.rstudio.com/tufte_handout_format.html
PDF output is cropped:
HTML output looks good:
Code snippet:
This produces the results above. I am not modifying it in the PDF and HTML versions.
```{r}
# names(dat)
# "__Backups" "__Budget" "__Comments" "__Documents" "__globals" "__KPI" "__Marketing Activities" "__MarketManager" "__Segmentation" "__sts_Account" "__sts_Budget" "__sts_Mandate" "__sts_ProfitCenter" "__UserLog" "__VL_PlanningStatus"
```
Use the chunk option tidy = TRUE.
tidy: (FALSE; logical) whether R code should be tidied up using the function tidy_source() in the formatR package; if it failed to tidy up, original R code will not be changed; tidy=TRUE is like keep.source=FALSE in Sweave, but it also tries not to discard R comments (N.B. this option does not work in certain cases; see http://yihui.name/formatR for more information)
---
title: "fmodbc Package"
author: "Bobby Rohrkemper, Software Developer at Schweiz Tourismus"
date: "`r Sys.Date()`"
# output:
# rmarkdown::html_vignette:
# toc: TRUE
output:
pdf_document:
toc: TRUE
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r}
library(knitr)
opts_chunk$set(tidy = TRUE)
```
```{r}
# names(dat)
# "__Backups" "__Budget" "__Comments" "__Documents" "__globals" "__KPI" "__Marketing Activities" "__MarketManager" "__Segmentation" "__sts_Account" "__sts_Budget" "__sts_Mandate" "__sts_ProfitCenter" "__UserLog" "__VL_PlanningStatus"
```
I am writing my first .rmd report using RMarkdown and then I knit it to pdf file. As I write it in my national language, I would like to have figures captions in my language too. The problem is that the default caption format is "Figure 1: My caption". I would like to change this generative "Figure 1:" part but I couldn't find how. Any help will be appreciated.
Try specifying the language in the YAML header of an rmarkdown document (documentation link):
---
title: "Crop Analysis Q3 2013"
output: pdf_document
fontsize: 11pt
geometry: margin=1in
lang: german
---
The language code will be processed by the babel LaTeX package (at least in the case of pdflatex).
I found out that it is possible to do using LaTeX:
---
title: "My raport"
output:
pdf_document:
fig_caption: yes
header-includes:
- \usepackage{caption}
---
\def\figurename{MyFigureName}
Still: is there any simpler way?
It should work like this:
---
output:
pdf_document:
fig_caption: true
---
```{r figWithCaption, echo=F, fig.cap="My Figure Caption"}
plot(cars) # your figure
```
I am attempting to create an rmarkdown document. I have finally figured out a way to approach this, although it has taken quite some time. The last thing I would like to be able to do is to add an image to the title page of my pdf document.
The trouble I have is that my title page is defined by the top section of YAML. Below is the contents of my example.Rmd file. I use the Knit PDF button in RStudio to turn it into a PDF.
---
title: "This is a my document"
author: "Prepared by: Dan Wilson"
date: '`r paste("Date:",Sys.Date())`'
mainfont: Roboto Light
fontsize: 12pt
documentclass: report
output:
pdf_document:
latex_engine: xelatex
highlight: tango
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
If anyone has some tips that would allow me to put an image (logo.png) above my title that would be great.
Based on the previous solution, the following code does not require an auxiliary header.tex file. All contents are contained in the .Rmd file. The LaTeX commands are instead defined in a header-includes block in the YAML header. More info can be found here.
Replace my_graphic.png below with your local graphic file.
---
title: "A title page image should be above me"
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}\LARGE\includegraphics[width=12cm]{my_graphic.png}\\[\bigskipamount]}
- \posttitle{\end{center}}
output:
pdf_document:
toc: true
---
\newpage
# Section 1
Some text.
I was able to solve this using LaTeX package titling
---
title: "Untitled"
author: "Name"
date: "September 19, 2015"
output:
pdf_document:
includes:
in_header: header.tex
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Where the header.tex should include the following code:
\usepackage{titling}
\pretitle{%
\begin{center}
\LARGE
\includegraphics[width=4cm,height=6cm]{logo.png}\\[\bigskipamount]
}
\posttitle{\end{center}}
and replace logo.png with the image you would like to use and make sure the file is in the root directory of your Rmd file. You can change image width and height to your needs. For more information on available options go to titling
For a beamer presentation you can do it like this:
title: "Title"
subtitle: "Subtitle"
author: "author"
date: "date"
header-includes:
- \titlegraphic{\centering \includegraphics[width=12cm]{titlepic.png}}
output:
beamer_presentation:
latex_engine: xelatex
theme: "metropolis"
highlight: "espresso"
classoption: "aspectratio=169"
The titlegraphic will be placed below your title text
For beamer presentation if you want an image at the bottom you can kind of cheat and add the image where the date line should be. Then if you want to insert date you can add institution (which is before date). the ![] should be tabbed (4 spaces from the far left of the page)
date: |
![](mypathtofile/myimage.png){width=3in}