Eva
Eva

Reputation: 861

How can I define and use a new "environment" in Quarto in R?

I am preparing a document using Quarto in RStudio. The output will be a LaTeX/PDF document, with the document class scrbook. In this book, I want to start each chapter with "Learning Objectives". The desired output will look like this:

----("hrulefill" in LaTeX)
Learning Objectives (Written in Bold Font)

In this chapter, you will learn
 - Topic 1
 - Topic 2
 - Topic 3
---- ("hrulefill" in LaTeX)

I want to keep the formatting of this "Learning Objectives" part like the "abstract" environment in LaTeX class scrreprt (i.e., more space in Left Margin and Right Margin, and a different font for the text). The issue is that "abstract" is not defined for scrbook document class.

My _quarto.yml file looks like the following:

project:
  type: book

book:
  title: "My Book Title"
  author: "Eva"
  date: today
  date-format: DD/MM/YYYY
  #cover-image: cover.jpeg
  chapters:
    - index.qmd
    - part: Basics.qmd
      chapters:
        - chapter_one.qmd
        - chapter_two.qmd
        - chapter_three.qmd
    - part: Intermediate.qmd
      chapters:
        - chapter_four.qmd
        - chapter_five.qmd
        - Conclusion.qmd
    - part: Appendix.qmd
      chapters:
        - Packages.qmd
        - Datasets.qmd
        - Code_Snippets.qmd

#bibliography: references.bib
format:
  html:
    theme: cosmo
  pdf:
    documentclass: scrbook
    colorlinks: true
    toc: true
    toc-title: "Contents"
    lot: true
    lof: true
    number-sections: true
    fig-cap-location: bottom
    tbl-cap-location: top
    code-line-numbers: true
    keep-tex: true
    author-meta: "Eva"
    title-meta: "My Book Title"
    hyperrefoptions:
    - linktoc=all
    - pdfwindowui
    - pdfpagemode=FullScreen
execute: 
  echo: true
  warning: false
  message: false
  error: false
  cache: true
editor: visual

So, I have two questions here:

(1) How can I define such environment myself?

(2) Where should I put this code in Quarto?

Upvotes: 0

Views: 494

Answers (1)

Julian
Julian

Reputation: 9290

From this post, you might be able to modify it to your liking:

format:
  pdf:
    documentclass: scrbook
    include-in-header: 
      - text: |
          \providecommand{\abstractname}{Learning Objectives} % not in scrbook class
          \newenvironment{secabstract}[1]{%
          \hrule
          \small\textbf{\abstractname: } 
          \newline
          \vspace{0.1cm}
          %\small\emph #1     %  emph takes an argument
          \small\emph{#1} % or \small\textit{#1} 
          \itshape % use this if you want the text to be in italics
          }{%
          \newline\hrule
          \vspace{0.6cm}
          }

chapter_one.qmd:

# Introduction

\begin{secabstract}{In this chapter, you will learn}

Topic 1

Topic 2

Topic 3
\end{secabstract}

Output:

enter image description here

Upvotes: 2

Related Questions