简体   繁体   中英

How can you change the table of contents line spacing in Quarto when rendering to a PDF?

I am using Quarto for my dissertation and wish to change the table of contents line spacing to 1 when rendering to a PDF. I have my line spacing for the rest of the document set to 1.5 using linestretch: 1.5 .

I have tried making up commands such as toc-linestretch: 1.5 , which has not worked for me. From the basic documentation , I don't see how to change the toc spacing to 1 and keep the rest of the document spacing to 1.5. If anyone knows how to do this within the _quarto.yml file, please let me know!

I have also tried to make a custom toc.text file as a LaTeX/template partial , but so far it's not working. I based my toc.tex file on the defaul template provided in the Quarto source code (scroll to line ~337). My current toc.tex file is:

\usepackage{setspace}
\setstretch{1}
$if(has-frontmatter)$
\mainmatter
$endif$
$body$

I expected \setstretch{1} to work, but this is my first experience with LaTeX, so I wouldn't be surprised if my toc.tex file has issues, but I'm not sure what to try next. Thanks!

The toc.tex file you have provided here doesn't contain the necessary command ( \tableofcontents ) to generate the table of contents and you don't need to use the template.tex if you just need to modify the toc, you may use just the toc.tex instead.

So you can try to use the following toc.tex file (which I have modified a bit by removing lines for beamer format)

toc.tex

{\setstretch{1} % set the linestrech from here ------------------------
$if(toc)$
$if(toc-title)$
\renewcommand*\contentsname{$toc-title$}
$endif$
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
$endif$
} % upto here ---------------------------------------------------------

$if(lof)$
\listoffigures
$endif$
$if(lot)$
\listoftables
$endif$

And then put the \usepackage{setspace} under include-in-header yaml key in the _quarto.yml file.

_quarto.yml

project:
  type: book

book:
  title: "Book"
  author: "Jane Doe"
  date: "1/4/2023"
  chapters:
    - index.qmd
    - intro.qmd
    - summary.qmd
    - references.qmd

bibliography: references.bib

format:
  pdf:
    documentclass: scrreprt
    linestretch: 1.5
    include-in-header:
      text: |
        \usepackage{setspace}
    template-partials: 
      - toc.tex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM