Search code examples
rpdflatexpandocquarto

Why do the same affiliation is repeated in the pdf output of quarto?


The quarto document quarto-file.md repeats the same affiliations:

---
title: "Hey!"
author:
  - name: Birdy Bird
    affiliations:
      - University of Birds
  - name: None
    affiliations:
      - University of Birds
format: 
  pdf:
    keep-tex: true
    template-partials: 
      - title.tex
    include-in-header:
      text: |
        \usepackage[noblocks]{authblk}
        \renewcommand*{\Authsep}{, }
        \renewcommand*{\Authand}{, }
        \renewcommand*{\Authands}{, }
        \renewcommand\Affilfont{\small}
---

## Quarto

Quarto enables you to weave together content and executable code into a finished
document. To learn more about Quarto see <https://quarto.org>.

quarto-file-render

I want the same affiliations not to be repeated, but this does not work using the title.tex in the answer to a similar question:

$if(title)$
\title{$title$$if(thanks)$\thanks{$thanks$}$endif$}
$endif$

$if(subtitle)$
\subtitle{$subtitle$}
$endif$

$for(by-author)$
\author[$for(by-author.affiliations)$$it.number$$sep$,$endfor$]{$by-author.name.literal$}
$endfor$

$for(by-author)$
$if(by-author.affiliations)$
$for(by-author.affiliations)$
\affil[$it.number$]{$if(by-author.affiliations.name)$$by-author.affiliations.name$$endif$}
$endfor$
$endif$
$endfor$


\date{$date$}

How to make the same affiliations to appear only once (with the same superscript)?


Solution

  • The use of authors-block has a major flaw in that, it adds the affiliations in the document body not in the document preamble (which you can verify if you look into the underlying tex file) which results in a large gap between the authors name and affiliations and also if you use abstract, the affiliations will be positioned after the abstract, which is visually not good.

    Therefore, I think, the use of title.tex latex-partial to accommodate the authblk latex package should be preferable for proper and nice formatting of the affiliations.

    Now the key thing to note that the option affil-id which needs to be a number that will link the authors and their affiliations and it will correspond to the id under the affiliations key.

    ---
    title: "Hey!"
    abstract: This is the abstract of the document. And you can see the author affiliations is nicely formatted.
    author:
      - name: Birdy Bird
        affil-id: 1
      - name: None
        affil-id: 1
    
    affiliations: 
      - id: 1
        name: University of Birds
    format: 
      pdf:
        keep-tex: true
        template-partials: 
          - title.tex
        include-in-header:
          text: |
            \usepackage[noblocks]{authblk}
            \renewcommand*{\Authsep}{, }
            \renewcommand*{\Authand}{, }
            \renewcommand*{\Authands}{, }
            \renewcommand\Affilfont{\small}
    ---
    
    ## Quarto
    
    Quarto enables you to weave together content and executable code into a finished
    document. To learn more about Quarto see <https://quarto.org>.
    

    title.tex

    $if(title)$
    \title{$title$$if(thanks)$\thanks{$thanks$}$endif$}
    $endif$
    
    $if(subtitle)$
    \subtitle{$subtitle$}
    $endif$
    
    $for(by-author)$
    \author$if(it.metadata.affil-id)$[$it.metadata.affil-id$]$endif${$it.name.literal$}
    $endfor$
    
    $if(by-affiliation)$
    $for(by-affiliation)$
    \affil[$it.id$]{$it.name$}
    $endfor$
    $endif$
    
    
    \date{$date$}
    

    Nicely formatted author affiliations


    And to add multiple affiliations per author, specify the affiliation id numbers (comma separated) in the affil-id key. See the updated answer here for example.