Search code examples
latexr-markdownrstudioquarto

How can I use different margins for the title page in Quarto pdf book?


I am creating PDF book using Quarto in RStudio. I use geometry package to specify margins in it. In particular, I want the margins on the title page different from other pages. The title page margins should be

geometry:
      - top=25.4mm
      - left=25.4mm
      - right=25.4mm
      - bottom=25.4mm

But I want different left-margin on all the other pages. The margins on all the other pages should be

geometry:
      - top=25.4mm
      - left=38.1mm
      - right=25.4mm
      - bottom=25.4mm

How can I do this?


Solution

  • Using template partials, you can specify different geometry for the title page and after the title page, you can restore the geometry for other pages.

    To do that you need to create a before-body.tex file as a partial latex template and inside that file, specify the new margin for the title page as suggested here.

    before-body.tex

    $if(has-frontmatter)$
    \frontmatter
    $endif$
    
    %------------------------------------------------
    % Declaring new geometry for the title page only.
    \newgeometry{margin=25.4mm}
    %------------------------------------------------
    
    $if(title)$
    $if(beamer)$
    \frame{\titlepage}
    $else$
    \maketitle
    $endif$
    
    %-----------------------------------------------
    % Ending the declared geometry for the title page
    % and restore the geometry for other pages
    \restoregeometry
    %-----------------------------------------------
    
    $if(abstract)$
    \begin{abstract}
    $abstract$
    \end{abstract}
    $endif$
    $endif$
    

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

    _quarto.yml

    project:
      type: book
    
    book:
      title: "Different Margins for Title Page"
      author: "Shafee"
      date: "7/31/2022"
      chapters:
        - index.qmd
        - intro.qmd
        - summary.qmd
        - references.qmd
    
    bibliography: references.bib
    
    format:
      pdf:
        documentclass: scrreprt
        include-in-header: 
          text: \usepackage[showframe, top=25.4mm, left=38.1mm, right=25.4mm, bottom=25.4mm]{geometry}
        template-partials:
          - before-body.tex
        
    

    Doing so you will have different margin for title page than all other pages for you book.


    Title Page

    Title page

    Other page

    Other page


    Note that I have used the showframe option of geometry package just to show that the margin changed. When you are done with testing with margin remove that option.

    include-in-header: 
          text: \usepackage[top=25.4mm, left=38.1mm, right=25.4mm, bottom=25.4mm]{geometry}