I want to make a cover page for my thesis. Something like this would be great. It's there a way to do it in R Markdown? Or maybe in a .tex file and then add it to the .rmd? I'm knitting into a pdf.
You can try to put a LaTeX Preamble into the .Rmd document. Change test.tex to the file path of your preamble. The preamble should only contain LaTeX code that comes after your \documentclass{article} declaration and before your \begin{document} declaration.
Output:
pdf_document:
includes:
in_header: “test.tex”
in that preamble you can try this for a custom title page:
\usepackage{titling}
\title{\huge{<++>}}
\author{\href{mailto:your#email.com}{Author Name}}
\date{\today}
and to render the title page put this in the .Rmd towards the top of the document:
\begin{titlepage}
\maketitle
\thispagestyle{empty}
\clearpage
\end{titlepage}
You could also try TeX Stack Exchange for lots of LaTeX questions.
Related
I would like to produce a custom title page when I knit my R Markdown document to pdf.
Here are the contents of my R Markdown document:
---
output:
pdf_document:
template: template.tex
---
# abstract
this is just some text
And here are the contents of template.tex:
\begin{document}
\maketitle
\end{document}
When I knit to pdf none of the R Markdown text appears. Only the template does.
Could anyone explain how I could type in R Markdown after using a latex template?
Your R Markdown document seems correct. The issue lies in your template.tex document.
This page shows a simple template.tex example:
\documentclass{article}
\begin{document}
$body$
\end{document}
The point of the example is to showcase that the contents of your markdown will be converted to LaTeX and inserted into where the $body$ is located. Therefore, the contents of your markdown are not showing up because there is no $body$ present in your template where the generated LaTeX might be inserted.
However, when I try to use the simple template, I receive an error about an undefined control sequence. This is because a specific LaTeX command is being inserted, but a requisite LaTeX package containing that command is not being loaded.
I am unsure what you want your title page to look like, but here is a working, simple-example of a template that contains a title page consisting of just the title.
\documentclass[]{report} % use report class because it contains a title page
\usepackage{hyperref} % load the hyperref package to avoid an undefined
% control sequence error
\title{$title$} % set title to what you passed from the yaml in the R
% Markdown document
\author{} % set author to empty to avoid warning message about
% no author set; use \author{$author$} if you want to
% set author from the yaml like `author: "My Name"`
\date{} % set date to empty to avoid a date on the title page;
% use \date{$date$} to set from yaml `date: 2021-01-08`
\begin{document}
\maketitle
$body$
\end{document}
But that template is pretty simple, and you will quickly run into additional undefined errors as you attempt to do more in your R Markdown document than what you have showed.
I recommend starting with the default LaTeX template of Pandoc and tweaking that to get where you want to go. The default LaTeX template of Pandoc can be found at https://github.com/jgm/pandoc/tree/master/data/templates (named default.latex).
In fact, you might be able to use the default template as is and just change your yaml because the following will create a title page as above:
---
title: "My Super Awesome Title"
documentclass: report
output: pdf_document
---
# abstract
this is just some text
I would like to produce a custom title page when I knit my R Markdown document to pdf.
Here are the contents of my R Markdown document:
---
output:
pdf_document:
template: template.tex
---
# abstract
this is just some text
And here are the contents of template.tex:
\begin{document}
\maketitle
\end{document}
When I knit to pdf none of the R Markdown text appears. Only the template does.
Could anyone explain how I could type in R Markdown after using a latex template?
Your R Markdown document seems correct. The issue lies in your template.tex document.
This page shows a simple template.tex example:
\documentclass{article}
\begin{document}
$body$
\end{document}
The point of the example is to showcase that the contents of your markdown will be converted to LaTeX and inserted into where the $body$ is located. Therefore, the contents of your markdown are not showing up because there is no $body$ present in your template where the generated LaTeX might be inserted.
However, when I try to use the simple template, I receive an error about an undefined control sequence. This is because a specific LaTeX command is being inserted, but a requisite LaTeX package containing that command is not being loaded.
I am unsure what you want your title page to look like, but here is a working, simple-example of a template that contains a title page consisting of just the title.
\documentclass[]{report} % use report class because it contains a title page
\usepackage{hyperref} % load the hyperref package to avoid an undefined
% control sequence error
\title{$title$} % set title to what you passed from the yaml in the R
% Markdown document
\author{} % set author to empty to avoid warning message about
% no author set; use \author{$author$} if you want to
% set author from the yaml like `author: "My Name"`
\date{} % set date to empty to avoid a date on the title page;
% use \date{$date$} to set from yaml `date: 2021-01-08`
\begin{document}
\maketitle
$body$
\end{document}
But that template is pretty simple, and you will quickly run into additional undefined errors as you attempt to do more in your R Markdown document than what you have showed.
I recommend starting with the default LaTeX template of Pandoc and tweaking that to get where you want to go. The default LaTeX template of Pandoc can be found at https://github.com/jgm/pandoc/tree/master/data/templates (named default.latex).
In fact, you might be able to use the default template as is and just change your yaml because the following will create a title page as above:
---
title: "My Super Awesome Title"
documentclass: report
output: pdf_document
---
# abstract
this is just some text
I want to use tikz as graphics device in RMarkdown and I want it to include the generated LaTeX preamble.
In the past, I already used tikzDevice within knitr documents. The tex file generated by tikzDevice usually included the whole preamble from my knitr/LaTeX document. When I use it with RMarkdown, I get the standard preamble (see below).
RMarkdown file:
---
title: "Title"
author: "Me"
fontsize: 12pt
documentclass: scrartcl
output:
bookdown::pdf_document2:
toc: true
fig_caption: true
keep_tex: true
---
# Introduction
```{r plot, dev="tikz"}
plot(rnorm(50))
``
Beginning of generated tex file (plot-1.tex):
% Created by tikzDevice version 0.12.3 on 2019-06-16 16:09:40
% !TEX encoding = UTF-8 Unicode
\documentclass[10pt]{article}
Desired/expected beginning of plot-1.tex:
% Created by tikzDevice version 0.12.3 on 2019-06-16 16:09:40
% !TEX encoding = UTF-8 Unicode
\documentclass[12pt]{scrartcl}
I'm not sure you really want what you're asking for. The figure will be produced as a separate document containing nothing except the figure, which will be rendered as a PDF. The differences between scrartcl and article shouldn't matter for the figure, they matter for the document as a whole.
But if you really do need that document class, you get it by specifying options(tikzDocumentDeclaration = "\\documentclass[12pt]{scrartcl}") in an R chunk early in your document. When I do that I can see in the source that it worked, but the output looks pretty much the same as it did with the default class. It's also possible to specify this using chunk options, but there's unlikely to be any advantage to doing that.
I think I figured it out:
My problem was that while using RMarkdown the options tikzDocumentDeclaration, tikzLatexPackages ... (nearly all options for tikzDevice) were not set automatically. When you use knitr the options for tikzDevice get set up in the process of splitting up markup and code chunks from the source file. With RMarkdown there is no LaTeX code to extract and use with tikz because pandoc generates it after the graphic is rendered. So one can either define the tikz... options manually or use the chunk option external=FALSE like user2554330 suggested.
Example minimal_knitr.Rnw:
\documentclass[fontsize=12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
<<r plot, dev='tikz', echo=FALSE>>=
plot(rnorm(50))
#
\end{document}
I´m not a LaTex user...actually started learning something about it as consequence of dynamic document I´m working with for a book document class I´m writing in R and knitr.
I´ve tried to customize the chapter headings, but meanwhile I did not get....I found the way to do this by LaTex (https://tex.stackexchange.com/questions/73421/how-to-create-specific-chapter-style-in-book-documentclass) however I´m not knowing how to address by RMardkown.
Does anybody could help me with that? How can I arrange the below LaTex commands to be triggered by RMarkdown (by .sty file?) or something similar way to customize the chapter heading in output pdf?
\documentclass{book}
\usepackage{titlesec}
\usepackage{lipsum} % just to generate text for the example
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{1ex}
{\titlerule\vspace{1ex}\filleft}
[\vspace{1ex}\titlerule]
Thanks
Fabio
You can put the stuff you want in the header, except the documentclass line, in a seperate tex file (I use header.tex below). You can then specify in the header of your R-markdown file that you want to include this file in the header. The documentclass van also be set in the header of your R-markdown file. More info on this can be found on the rstudio site.
Below an example:
---
title: "Untitled"
output:
pdf_document:
includes:
in_header: header.tex
documentclass: book
---
\chapter{Introduction}
Section
=======
This is an R Markdown document.
header.tex looks like:
\usepackage{titlesec}
\usepackage{lipsum} % just to generate text for the example
\titleformat{\chapter}[display]
{\bfseries\Large}
{\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
{1ex}
{\titlerule\vspace{1ex}\filleft}
[\vspace{1ex}\titlerule]
I'm trying to add frame numbers to my Beamer presentation written in rmarkdown. However, I would like to suppress the numbers on the title page using the \begin{frame}[plain] option (from the second answer here: https://tex.stackexchange.com/questions/82794/removing-page-number-from-title-frame-without-changing-the-theme). However, when compiling from rmarkdown to tex, the \titlepage already creates a frame environment, so in effect I get a double frame and thus an error.
So when compiling this:
---
output:
beamer_presentation:
includes:
in_header: header.tex
---
\begin{frame}[plain]
\titlepage
\end{frame}
I get this in latex:
\begin{frame{
\begin{frame}
\titlepage
\end{frame}
\end{frame}
In the header.tex I have this:
\let\otp\titlepage
\renewcommand{\titlepage}{\otp\addtocounter{framenumber}{-1}}
So my workaround now is to just use a plain \maketitle in rmarkdown, then compile to .tex, add the [plain] option, then compile to pdf. However, I would like to avoid that intermediate step. Is this possible in rmarkdown?
rmarkdown uses pandoc to convert a Rmd file to a pdf via beamer/latex. pandoc uses templates to control how the conversion goes.
One way to deal with your problem is to :
Download the default beamer template rmarkdown uses and open it.
Change line 137 from this :
\frame{\titlepage}
To this :
\frame[plain]{\titlepage}
Add the path to your modified template in your Rmd file :
---
output:
beamer_presentation:
includes:
in_header: header.tex
template:/path/to/new/template.tex
---
Note that you need to specify the whole path, or store the template where pandoc can find it (~/.pandoc/templates on a linux machine)
Add {.plain} after the title as in:
----
# I'm the title {.plain}
Source: Pandoc User’s Guide