1

I am using Quarto inside RStudio to create a book project. The output will be a pdf/LaTeX file. Quarto originally puts the Table of Content just after the title page. But I need to put the abstract, preface and acknowledgements first before the Table of Contents. How can I change this sequence? Is it possible to change this sequence using _quarto.yml file or do I need to change it through LaTeX?

shafee
  • 15,566
  • 3
  • 19
  • 47
Eva
  • 663
  • 5
  • 13

1 Answers1

4

You can do this using template-partials

To do that you need to create a before-body.tex file as a partial latex template and put all the necessary latex code that will go before the table of contents, list of figures, list of tables, and rest of the document.


before-body.tex

$if(has-frontmatter)$
\frontmatter
$endif$

$if(title)$
\maketitle
$endif$

\newpage

%----------------------------------------------
%   Abstract
%----------------------------------------------

\begin{center}
\Large{Abstract}
\end{center}

\vspace*{\baselineskip}

This is the Abstract part

\newpage

%----------------------------------------------
%   Preface
%----------------------------------------------

\begin{center}
\Large{Preface}
\end{center}

\vspace*{\baselineskip}

This is the Preface part

\newpage

%----------------------------------------------
%   Acknowledgement
%----------------------------------------------

\begin{center}
\Large{Acknowledgement}
\end{center}

\vspace*{\baselineskip}

This is the acknowledgement part

\newpage


Then to add this template, use the template-partials option in _quarto.yml

_quarto.yaml

project:
  type: book

book:
  title: "Quarto book"
  author: "Shafee"
  date: "7/31/2022"
  chapters:
    - index.qmd
    - intro.qmd

format:
  pdf:
    toc: true
    documentclass: scrreprt
    template-partials:
      - before-body.tex

Also, create the partial file named exactly as before-body.tex, since per the documentation,

Note that the name of the partial files is important. You choose which portion of the template to replace by providing a partial with that name.

shafee
  • 15,566
  • 3
  • 19
  • 47
  • 2
    Thanks a lot for solving my Quarto/LaTeX problems. – Eva Aug 11 '22 at 01:58
  • 1
    I upvoted your answer. And so far, I thought upvoting means accepting your answer. But after your comment, I saw that there is a tick mark symbol too, to accept the answer. Really sorry about that. – Eva Aug 11 '22 at 02:03
  • This solution is a pdf only solution. You need to write the content before the toc as LaTeX. Hence you no longer can generate both a pdf and an HTML from the same source code. – Thierry Aug 22 '22 at 17:38
  • @Thierry, yes this is a pdf only solution (and I believe the OP wanted to solve this for pdf only) but I think its also possible to do in case of HTML too, since quarto also provides [`HTML partials`](https://quarto.org/docs/journals/templates.html#html-partials) – shafee Nov 02 '22 at 13:18