Thesis using Quarto

Dr. Ajay Kumar Koli \(\cdot\) 2nd SARA Bootcamp

Thesis
Structure

Set Up GitHub Repo

Create a new GitHub repository (repo) for your book project.

 

Create Version Control RStudio Project

Paste the Repo Link/URL

Set Up RStudio Project

Create a file named _quarto.yml. It will contain the configuration settings for your thesis.

Configure _quarto.yml:

project:
  type: book

book:
  title: "My Book Title"
  author: "Author Name"
  date: "2023-10-01"
  chapters:
    - index.qmd
    - chapter1.qmd
    - chapter2.qmd

format:
  html:
    theme: cosmo
  pdf:
    documentclass: scrreprt

Create Content Files

  • Create the content files for your chapters (e.g., index.qmd, chapter1.qmd, chapter2.qmd).

  • Write your content using Markdown syntax. You can also include code, figures, and other elements.

Example index.qmd

---
format: html
---

# Introduction

Welcome to my book. This is the introduction chapter.

Example chapter1.qmd

---
format: html
---

# Chapter 1

This is the content of Chapter 1.

Render the Book

Preview and Iterate (html)

Preview and Iterate (pdf)

Thesis Text
Formating

Markdown


Markdown is a lightweight markup language for creating formatted text using a plain-text editor. Developed by John Gruber in 2004.

Text formatting


Markdown Syntax Output
normal
normal
*italics*
italics
**bold**
bold
***bold italics***
bold italics

Text formatting


Markdown Syntax Output
superscript^2^
superscript2
subscript~2~
subscript2
~~strike through~~
strike through
`verbatim code`
verbatim code

Headings


Markdown Syntax Output
# Header 1

Header 1

## Header 2

Header 2

### Header 3

Header 3

#### Header 4

Header 4

##### Header 5
Header 5
###### Header 6
Header 6

Add images

If image is saved in your computer,
![](add image path here)


Markdown Syntax Output
![](banner.png)
|

Add images

If image is taken from the internet,
![](add image link here)


![](https://images.unsplash.com/photo-1627130595904-ebeeb6540a93?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D)

Unordered list


Markdown Syntax Output
* Item 1
* Item 2
* Item 3
  • Item 1
  • Item 2
  • Item 3

Unordered list: Sub-items


Markdown Syntax Output
* Main items
    + Sub-item 1
    + Sub-item 2
        - Sub-sub-item 1
  • Main items
    • Sub-item 1
    • Sub-item 2
      • Sub-sub-item 1

Ordered list


Markdown Syntax Output
1. Eggs
1. Tea
1. Fish
1. Milk
  1. Eggs
  2. Tea
  3. Fish
  4. Milk

List


Markdown Syntax Output
(@)  A list whose numbering

continues after

(@)  an interruption
  1. A list whose numbering

continues after

  1. an interruption

List


Markdown Syntax Output
::: {}
1. A item
1. B item
:::

::: {}
1. Followed by another list
:::
  1. A item
  2. A item
  1. Followed by another list

Equations

Use $ delimiters for inline math.


Markdown Syntax Output
It is a great equation $E = mc^{2}$
It is a great equation \(E=mc^{2}\)

Equations

Use $$ delimiters for display math.


Markdown Syntax Output
It is a great equation $$E = mc^{2}$$
It is a great equation \[E=mc^{2}\]

In-line coding

`{r} `

```{r}

age <- c(1, 2, 3, 4, 5)

```

Input: The mean age of the participants is `{r} mean(age)`.

Output: The mean age of the participants is 3.

Tables,
Figures &
Data in
a Thesis

What We Will Cover Now

  • πŸ“Š Adding Tables (Markdown β†’ kable β†’ kableExtra)
  • πŸ–ΌοΈ Adding Figures (Images β†’ Code β†’ ggplot)
  • πŸ”— Cross-Referencing Tables & Figures
  • πŸ“ Loading & Displaying Real Data
  • 🎯 Hands-on Your Turn Exercises

πŸ“Š Adding Tables

Step 1: Markdown Table (Simplest)

Type this in your .qmd file:

| Name  | Age | City     |
|-------|-----|----------|
| Ajay  | 25  | Delhi    |
| Kiram | 30  | Sonipat  |

Output:

Name Age City
Ajay 25 Delhi
Kiram 30 Sonipat

Step 2: kable Table

```{r}
# call the r package
library(knitr)

kable(head(mtcars), 
      caption = "My First Table")
```


Note

kable() is the go-to function for simple, clean tables in R.

Step 3: kableExtra (Styled Tables)

```{r}
library(kableExtra)

kable(head(mtcars), caption = "Styled Table") |>
  kable_styling(
    bootstrap_options = "striped",
    full_width = FALSE
  )
```
  • striped β€” alternating row colors
  • hover β€” highlight on mouse hover
  • condensed β€” compact layout

🎯 Your Turn: Tables

Exercise 1

Create a table showing 5 rows of any dataset of your choice.

βœ… Add a caption
βœ… Make it striped
βœ… Set full_width = FALSE

πŸ–ΌοΈ Adding Figures

Step 1: Insert an External Image

![Figure Caption](images/my-photo.png){
  fig-alt="description" 
  width="70%"
}


Tip

Always add fig-alt for accessibility β€” it’s good research practice!

Step 2: Figure from R Code

```{r}
#| label: fig-cars
#| fig-cap: "Relationship between Speed and Distance"

plot(cars$speed, cars$dist,
     xlab = "Speed", ylab = "Distance")
```
  • label β€” must start with fig- for cross-referencing
  • fig-cap β€” your figure caption

Step 3: ggplot Figure

```{r}
#| label: fig-ggplot
#| fig-cap: "MPG by Cylinder Count"
#| fig-width: 6
#| fig-height: 4
#| eval: false

library(ggplot2)

ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
  geom_boxplot(fill = "steelblue") +
  labs(x = "Cylinders", y = "MPG")
```

🎯 Your Turn: Figures

Exercise 2

  1. Insert any image from your computer
  2. Create a ggplot figure using the iris dataset
  3. Add a proper caption using fig-cap
  4. Set figure width and height

πŸ”— Cross-Referencing

Why Cross-Reference?

In a thesis, you write:

β€œAs shown in Figure 3.2, the results indicate…”

Quarto handles the numbering automatically - you just use labels!

Cross-Referencing Figures

In your code chunk:

#| label: fig-scatter

In your text:

As shown in @fig-scatter, there is a positive trend...


Important Rule

Figure labels must start with fig-
Table labels must start with tbl-

Cross-Referencing Tables

In your code chunk:

#| label: tbl-summary

In your text:

As seen in @tbl-summary, the results indicate...


Quarto automatically converts @tbl-summary \(\rightarrow\) Table 1

🎯 Your Turn: Cross-Referencing

Exercise 3

  1. Create one table with a tbl- label
  2. Create one figure with a fig- label
  3. Reference both somewhere in your text using @
  4. Render and check the automatic numbering

πŸ“ Real Data in Your Thesis

Loading Data

```{r}
# CSV file
data <- read.csv("data/survey.csv")

# Excel file
library(readxl)
data <- read_excel("data/survey.xlsx")

# Built-in dataset
data <- mtcars
```

Displaying Data as a Table

```{r}
#| label: tbl-data
#| tbl-cap: "Summary of Survey Data"

library(knitr)

kable(head(data))
```

Creating a Figure from Real Data

```{r}
#| label: fig-data
#| fig-cap: "Distribution of Responses"

hist(data$age, 
     main = "", 
     xlab = "Age",
     col = "steelblue")
```

🎯 Your Turn: Real Data

Exercise 4

Using the built-in airquality dataset:

  1. Display the first 6 rows as a kable table
  2. Create a histogram of the Temp column
  3. Add proper captions to both
  4. Cross-reference them in a short paragraph

πŸ“ Thesis-Specific Settings

Global Settings in _quarto.yml

execute:
  echo: false       # hide code in final thesis
  warning: false    # hide warnings
  message: false    # hide messages

format:
  html:
    fig-width: 7
    fig-height: 5


Tip

Set echo: false globally so your thesis shows only output, not code.

Useful Chunk Options

Option Purpose
echo: false Hide code, show output
eval: false Show code, don’t run it
fig-width: 7 Set figure width
fig-height: 5 Set figure height
tbl-cap Add table caption
fig-cap Add figure caption

Key Takeaway

In a Quarto thesis, everything is connected

Your data, code, and writing live in one place.

When data changes β†’ tables and figures update automatically.

Note

That is Reproducible Research in action! πŸŽ‰

Add
References

What We Will Cover Now

  • πŸ“– What is Zotero and why use it?
  • βš™οΈ Setting up Zotero with Quarto
  • πŸ“ Adding a bibliography to your thesis
  • ✍️ Inserting citations in your text
  • 🎨 Changing citation styles (APA, Chicago, etc.)
  • πŸ”— Connecting Zotero directly in RStudio
  • 🎯 Hands-on Your Turn Exercises

πŸ“– What is Zotero?

Zotero β€” Simply Put

Think of Zotero as a smart bookshelf for your research.

  • πŸ“š Saves all your papers, books, and articles in one place
  • 🏷️ Stores author, year, title, journal β€” automatically
  • πŸ“€ Exports references in any format Quarto needs
  • πŸ”„ Syncs across devices via zotero.org

Note

Zotero is free and open source β€” perfect for researchers!

Why Zotero + Quarto?

Without Zotero With Zotero + Quarto
Type references manually References inserted automatically
Format APA by hand Style applied instantly
Risk of typos Always accurate
Hard to update One click to refresh
Separate reference list Auto-generated bibliography

βš™οΈ Setting Up Zotero

Step 1: Install Zotero

  1. Go to zotero.org and download Zotero
  2. Install the Zotero Connector browser extension
  3. Create a free account at zotero.org/user/register
  4. Sign in inside the Zotero app

Tip

The browser extension lets you save a paper in one click while browsing Google Scholar or any journal website.

Step 2: Add References to Zotero

Three easy ways:

  • 🌐 Browser Connector β€” click the Zotero icon while on any paper page
  • πŸ” Search by DOI/ISBN β€” Edit β†’ Add Item by Identifier
  • πŸ“„ Import PDF β€” drag and drop a PDF into Zotero

Step 3: Install Better BibTeX Plugin

This plugin exports your library in a format Quarto understands.

  1. Go to github.com/retorquere/zotero-better-bibtex
  2. Download the .xpi file
  3. In Zotero β†’ Tools β†’ Add-ons β†’ Install Add-on From File
  4. Select the downloaded .xpi file
  5. Restart Zotero

Step 4: Export Your Library as .bib

  1. In Zotero, right-click your collection
  2. Select Export Collection
  3. Choose format: Better BibTeX
  4. βœ… Check Keep Updated β€” auto-syncs when you add new references!
  5. Save as references.bib inside your Quarto project folder

Warning

Save the .bib file in the same folder as your _quarto.yml

πŸ“ Linking Bibliography in Quarto

Add Bibliography to _quarto.yml

project:
  type: book

book:
  title: "My Thesis"
  author: "Your Name"

bibliography: references.bib
csl: apa.csl                  # citation style (optional)

format:
  html:
    theme: cosmo
  pdf:
    documentclass: scrreprt

Note

bibliography: tells Quarto where your references file lives.

Or Add to a Single Chapter’s YAML

If you only want bibliography in one .qmd file:

---
title: "Literature Review"
bibliography: references.bib
csl: apa.csl
---

✍️ Inserting Citations in Text

Citation Syntax β€” The Basics

Every reference in your .bib file has a citation key like:

@peng2011reproducible
@wickham2016ggplot2
@gandrud2016reproducible

How to Cite in Text

What you want Syntax Output
Author (Year) @peng2011 Peng (2011)
(Author, Year) [@peng2011] (Peng, 2011)
Multiple sources [@peng2011; @knuth1984] (Peng, 2011; Knuth, 1984)
Page number [@peng2011, p. 45] (Peng, 2011, p. 45)
Suppress author [-@peng2011] (2011)

Example in Your Thesis Text

Reproducible research has been defined as sharing data and 
code alongside findings [@peng2011].

As @buckheit1995 argued, the actual scholarship is the 
complete software environment that produced the results.

Several studies [@peng2011; @gandrud2016; @knuth1984] 
have emphasized the importance of literate programming.

The Bibliography Appears Automatically!

At the end of your document, Quarto automatically generates:

## References

Peng, R. D. (2011). Reproducible research in computational 
science. *Science*, 334(6060), 1226–1227.

Buckheit, J., & Donoho, D. (1995). WaveLab and reproducible 
research. *Wavelets and Statistics*, 55–81.

Tip

No need to type the reference list β€” Quarto does it for you! πŸŽ‰

🎯 Your Turn: First Citation

Exercise 1

  1. Add 3 references to your Zotero library
  2. Export as references.bib to your project folder
  3. Link it in your _quarto.yml
  4. Write one paragraph and cite all 3 sources
  5. Render and check the bibliography at the end

🎨 Citation Styles

What is a CSL File?

CSL = Citation Style Language

It controls how your citations look:

  • APA β†’ (Peng, 2011)
  • Chicago β†’ Peng, Roger D. 2011. β€œReproducible Research…”
  • Vancouver β†’ [1]
  • Harvard β†’ Peng (2011)
  • IEEE β†’ [1] R. D. Peng…

Download a CSL File

  1. Go to zotero.org/styles
  2. Search for your required style (e.g., APA 7th)
  3. Download the .csl file
  4. Place it in your Quarto project folder
  5. Add to _quarto.yml:
csl: apa.csl

Common CSL Files

Style File Name Used In
APA 7th apa.csl Social sciences
Chicago chicago-author-date.csl Humanities
Vancouver vancouver.csl Medicine
Harvard harvard-cite-them-right.csl General
IEEE ieee.csl Engineering

Tip

Check with your university which style they require for your thesis!

🎯 Your Turn: Change Citation Style

Exercise 2

  1. Download the APA 7th CSL file from zotero.org/styles
  2. Place it in your project folder
  3. Add csl: apa.csl to your _quarto.yml
  4. Render your document
  5. Now switch to Chicago style and render again
  6. Compare the difference!

πŸ”— Zotero Direct Integration in RStudio

The Easiest Way β€” Visual Editor

RStudio’s Visual Editor connects directly to Zotero!

  1. Open your .qmd file in RStudio
  2. Switch to Visual mode (top-left toggle)
  3. Go to Insert β†’ Citation
  4. Search your Zotero library directly!
  5. Click Insert β€” citation key added automatically

Note

No need to remember citation keys β€” RStudio finds them for you!

Visual Editor Citation Dialog

Insert β†’ Citation

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ” Search: reproducible        β”‚
β”‚                                 β”‚
β”‚  πŸ“š My Library                  β”‚
β”‚  β”œβ”€β”€ Peng 2011                  β”‚
β”‚  β”œβ”€β”€ Buckheit 1995              β”‚
β”‚  └── Gandrud 2016               β”‚
β”‚                                 β”‚
β”‚  [ Insert ]  [ Cancel ]         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Setting Up Zotero in RStudio

Make sure RStudio can find your Zotero:

  1. Tools β†’ Global Options β†’ R Markdown β†’ Citations
  2. Set Zotero Library to: Local or Web
  3. If Web: add your Zotero API key from zotero.org/settings/keys
  4. Click OK

Auto-Complete Citation Keys

In Source mode, type @ and start typing:

As shown by @pen...

RStudio will autocomplete from your .bib file:

@peng2011reproducible  ← select this!
@penman2019...

Tip

This works like autocomplete in coding β€” fast and accurate!

🎯 Your Turn: Visual Editor Citations

Exercise 3

  1. Open a .qmd file in Visual mode
  2. Use Insert β†’ Citation to search your Zotero library
  3. Insert 2 citations into a paragraph
  4. Switch to Source mode and observe the citation keys
  5. Render and check the output

πŸ“ Your .bib File β€” A Closer Look

What a .bib File Looks Like

@article{peng2011reproducible,
  title   = {Reproducible Research in Computational Science},
  author  = {Peng, Roger D},
  journal = {Science},
  volume  = {334},
  number  = {6060},
  pages   = {1226--1227},
  year    = {2011}
}

@book{gandrud2016reproducible,
  title     = {Reproducible Research with R and RStudio},
  author    = {Gandrud, Christopher},
  publisher = {CRC Press},
  year      = {2016}
}

Anatomy of a Citation Key

@article{peng2011reproducible,
          ^^^^^^^^^^^^^^^^^^^^
          This is the citation key you use in text
          
          Convention: AuthorYearKeyword
          e.g., peng2011reproducible
               wickham2016ggplot
               gandrud2016reproducible

Note

Better BibTeX generates these keys automatically for you!

πŸ› οΈ Troubleshooting

Common Problems & Fixes

Problem Fix
Citation not found Check the key matches exactly in .bib
Bibliography not showing Add bibliography: references.bib to YAML
Wrong style Check .csl file name and path
.bib not updating Re-export from Zotero with Keep Updated
RStudio can’t find Zotero Check Global Options β†’ Citations

Checklist Before Rendering

  • βœ… references.bib is in the project folder
  • βœ… bibliography: references.bib is in _quarto.yml
  • βœ… Citation keys in text match keys in .bib file
  • βœ… .csl file is downloaded and path is correct
  • βœ… Zotero is open (for live sync)

Key Takeaway πŸ”‘

Never format a reference manually again!

Zotero + Quarto means:

  • ✍️ You write β€” Quarto formats
  • πŸ“š You collect β€” Zotero organizes
  • 🎨 You choose the style β€” CSL applies it
  • πŸ”„ You add a source β€” bibliography updates automatically

πŸ’› Benefits of using Quarto

  1. Reproducibility

  2. Iterative Workflow

  3. Customization and Flexibility

  4. Multi-Format Output

  5. Collaboration

  6. Reduced Formatting Issues

  7. Integration with Other Tools

  8. Documentation and Support