6.5 PDF Options
Use the pdf format to create PDF output. For example:
---
title: "Lab 1: Solutions"
format:
pdf:
include-in-header: ../latex/preamble.tex
fontsize: 12pt
pdf-engine: xelatex
---See HERE for all available PDF options. All PDF options go inside the format: → pdf: chunk of the YAML.
See Metadata variables for yaml options that Pandoc recognizes.
Title & Author
| PDF Options | Functions |
|---|---|
title |
Document title |
date |
Document date |
author |
Author or authors of the document |
abstract |
Summary of document |
Format Options
| PDF Options | Functions |
|---|---|
pdf-engine |
Specify the PDF engine to use. Options include pdflatex, xelatex, and lualatex. The default is xelatex. |
| PDF Options | Functions |
|---|---|
include-in-header |
Include contents at the end of the header. Specify your pdf template here. |
Subkeys for include-in-header
file: path to a file to include at the end of the header.text: |: include raw latex content in the YAML header.|indicates that the content is in multiple lines.If you omit
file:ortext:, Quarto assumesfile:by default.
Use example
format:
pdf:
include-in-header:
- text: |
\usepackage{eplain}
\usepackage{easy-todo}
- file: packages.tex
- macros.tex # assume file by default- Note that you need the dash
-beforetext:andfile:to indicate a list of items.
Any packages specified using includes that you don’t already have installed locally will be installed by Quarto during the rendering of the document.
header-includes: | is a pandoc variable for including raw LaTeX code in the document header.
- use example in quarto doc
- pandoc doc for
header-includes
header-includes: |
\RedeclareSectionCommand[
beforeskip=-10pt plus -2pt minus -1pt,
afterskip=1sp plus -1sp minus 1sp,
font=\normalfont\itshape]{paragraph}
\RedeclareSectionCommand[
beforeskip=-10pt plus -2pt minus -1pt,
afterskip=1sp plus -1sp minus 1sp,
font=\normalfont\scshape,
indent=0pt]{subparagraph}Format & Typesettings
| PDF Options | Functions |
|---|---|
toc-depth: 3 |
Specify the number of section levels to include in the table of contents. The default is 3 |
number-sections: false |
Number section headings rendered output. By default, sections are not numbered. |
number-depth |
By default, all headings in your document create a numbered section. |
| PDF Options | Functions |
|---|---|
df-print |
Method used to print tables in Knitr engine documents. - default: Use the default S3 method for the data frame. - kable: Default method. Markdown table using the knitr::kable() function. - tibble: Plain text table using the tibble package. - paged: HTML table with paging for row and column overflow. |
| PDF Options | Functions |
|---|---|
keep-tex: false |
Whether to keep the intermediate tex file used during render. Defaults to false.Helpful when you want to debug or share tex files with others. |
Q: How to print dollar sign in pdf output?
A: qmd supports $ directly. No need to escape. If it fails, try \$ or \\$.
After rendering, the following info will appear in the console:
pandoc
to: latex
output-file: lab1_solutions.tex
standalone: true
pdf-engine: xelatex
variables:
graphics: true
tables: true
default-image-extension: pdf
metadata
documentclass: scrartcl
classoption:
- DIV=11
- numbers=noendperiod
papersize: letter
header-includes:
- \KOMAoption{captions}{tableheading}
block-headings: true
title: 'Lab 1: Solutions'
fontsize: 12pt
By default, Quarto uses the scrartcl document class and letter paper size for pdf output.
Note that documentclass: scrartcl is the KOMA-Script article class.
KOMA-Script classes have good looking default settings, and are highly customizable.
You can set documentclass to the standard article, report or book classes, to the KOMA Script equivalents scrartcl, scrreprt, and scrbook respectively, or to any other class made available by LaTeX packages you have installed.
6.5.1 Title Margin
One issue is it might have too wide margins around the title.
To reduce the margin above the title, add the following line to your preamble.tex file:
% reduce title top margin
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@maketitle}{\vskip2em}{
% Insert here the space you want between the top margin and the title.
\vspace{-2em} % Example of smaller margin.
}{}{}
\makeatotherTo reduce the margin below the title, in individual qmd file, add the following line after the YAML header:
fenced divs
code chunks
For pdf output, it is possible to write LaTeX code directly in Markdown document using fenced divs or code chunks with {=latex}.
- Don’t forget the equal sign before
latex.
ref: R Markdown Cookbook: Section 6.11 Write raw LaTeX code
6.5.2 Templates
See HERE for an overview of how to set template for tex files.
- pakage setup
- article typsetting
Starter template for qmd file.
- yaml header
- structure of your
qmd
6.5.3 Add Appendices
\newpage
# Appendices {.unnumbered}
\appendix
\renewcommand{\thesubsection}{\Alph{subsection}}
\setcounter{table}{0}
\renewcommand{\thetable}{\thesection\arabic{table}}
\setcounter{figure}{0}
\renewcommand{\thefigure}{\thesection\arabic{figure}}
## Optimal Portfolio R Code# Appendices {.unnumbered}creates a title for the appendices section without a section number.- Use
\appendixto reset the section counter to 0 and\renewcommand{\thesubsection}{\Alph{subsection}}to change the section numbering to letters (A, B, C, …). - Similarly, reset the table and figure counters and change their numbering to include the section letter “A”, “B”, … as a prefix.
- Finally, use
## Optimal Portfolio R Codeto create an appendix section for your first appendix. The# Appendiceswill be level one heading, and## Optimal Portfolio R Codewill be level two heading under the appendices section.