Home > Back-end >  How to change the font for hyperlinks in RMarkdown?
How to change the font for hyperlinks in RMarkdown?

Time:09-13

For a report I am writing recently in R Markdown, I would like to change the font for the links I put on the References section. The desired output I would like to have is like the below image;

enter image description here

My YAML front I am using to produce the R markdown document as like the following;

---
title: ""
author:
  - AAA
output:
  pdf_document:
    latex_engine: xelatex
    number_sections: true
geometry: "left = 2.5cm, right = 2.5cm, top = 2.5cm, bottom = 2.5cm"
fontsize: 12 pt
header-includes:
    - \usepackage {ragged2e}
    - \usepackage {titling}
    - \usepackage[nottoc]{tocbibind} 
    - \usepackage{float}
    - \usepackage{sectsty}
    - \usepackage{paralist}
    - \usepackage{setspace}
    - \usepackage{fancyhdr}
    - \usepackage{lastpage}
    - \usepackage{dcolumn}
    - \usepackage{natbib}
    - \usepackage{subcaption}
    - \usepackage{rotating}
    - \usepackage{placeins}
    - \usepackage{float}
    - \floatplacement{figure}{H}
link-citations: true
link-color: red
urlcolor: blue
biblio-style: apsr
linestretch: 2
ident: True
bibliography: ["aaa.bib"]
---

Therefore, I appreciate any comment or suggestion in changing the font type for the hyperlinks in the references section. Thank you for your attention beforehand.

CodePudding user response:

Option 1

One way could be using \urlstyle from url package. From the changed font for urls


Option 2

You can also change the fonts for url links, by defining a new command like \urlfont for loading a particular font family with \newfontfamily (read the changed url font - option 2


Do not put the commands \urlstyle{tt} or \def\UrlFont{\urlfont} in header-includes, because if you do that these commands will be overridden by \urlstyle{same} (default style set by r-markdown). So It's best to set these commands just before the reference section.

  • Related