如何在RMarkdown中为文中引用和图表超链接使用不同的颜色?

huangapple go评论69阅读模式
英文:

How can I use different colours for in-text citations and figure hyper-references in RMarkdown?

问题

Consider the following RMarkdown document:

---
output:
  pdf_document:
    number_sections: true
    fig_caption: yes
title: 'Title'
author:
  - Name
geometry: margin=1in
bibliography: references.bib
csl: something.csl
link-citations: yes
linkcolor: blue
urlcolor: black

header-includes:
 \usepackage{setspace}
 \usepackage{graphicx}
 \usepackage[colorlinks]{hyperref}
 \usepackage[all]{hypcap}
---

Lorem ipsum [@reference]

knitr::include_graphics("file.png")

Referencing to \autoref{fig:landscape}.

When I run this sort of document, I see the same hyper-linked color (blue) for both citations (like the [@reference] and references to the figure (the \autoref).

I want to be able to separate the coloring of my references and hyperlinks to figures in the same document (like blue for the Evanno et al., 2005 in the image and red for the Figure 2). How can I do this in RMarkdown? I've tried wrapping the \autoref{} in a \color{red}{\autoref{fig:landscape}} but this did not work.

英文:

Consider the following RMarkdown document:

---
output: 
  pdf_document:
    number_sections: true
    fig_caption: yes
title: 'Title'
author: 
  - Name
geometry: margin=1in
bibliography: references.bib
csl: something.csl
link-citations: yes
linkcolor: blue
urlcolor: black

header-includes:
 \usepackage{setspace}
 \usepackage{graphicx}
 \usepackage[colorlinks]{hyperref}
 \usepackage[all]{hypcap}
---

Lorem ipsum [@reference]

```{r landscape, echo=FALSE,include=TRUE,warning=FALSE,fig.cap="\\label{fig:landscape}Caption"}

knitr::include_graphics("file.png")

```

Referencing to \autoref{fig:landscape}.

When I run this sort of document, I see the same hyper-linked colour (blue) for both citations (like the [@reference] and references to the figure (the \autoref).

如何在RMarkdown中为文中引用和图表超链接使用不同的颜色?

如何在RMarkdown中为文中引用和图表超链接使用不同的颜色?

I want to be able to separate the colouring of my references and hyperlinks to figures in the same document (like blue for the Evanno et al., 2005 in the image and red for the Figure 2). How can I do this in RMarkdown? I've tried wrapping the \autoref{} in a \color{red}{\autoref{fig:landscape}} but this did not work.

答案1

得分: 2

我们可以按照这里描述的技术来定义一个用于引用图表的新命令。

---
title: 'Title'
output:
  pdf_document:
    number_sections: true
    fig_caption: yes
author:
  - Name
geometry: margin=1in
bibliography: reference.bib
link-citations: yes
linkcolor: blue
urlcolor: black
header-includes:
  \newcommand\figref[1]{{\hypersetup{linkcolor=red}\autoref{#1}}}
---

Lorem ipsum [@R-base]

```{r landscape, echo=FALSE, include=TRUE, warning=FALSE, fig.cap="\\label{fig:landscape}Caption"}

plot(1:10)

引用至\figref{fig:landscape}.


如何在RMarkdown中为文中引用和图表超链接使用不同的颜色?



<details>
<summary>英文:</summary>

We can follow the technique described [here](https://tex.stackexchange.com/a/226374/261065) to define a new command for figure referencing.

~~~
---
title: &#39;Title&#39;
output: 
  pdf_document:
    number_sections: true
    fig_caption: yes
author: 
  - Name
geometry: margin=1in
bibliography: reference.bib
link-citations: yes
linkcolor: blue
urlcolor: black
header-includes:
  \newcommand\figref[1]{{\hypersetup{linkcolor=red}\autoref{#1}}}
---

Lorem ipsum [@R-base]

```{r landscape, echo=FALSE,include=TRUE,warning=FALSE,fig.cap=&quot;\\label{fig:landscape}Caption&quot;}

plot(1:10)

Referencing to \figref{fig:landscape}.


&lt;hr&gt;

[![different color for figure reference][1]][1]


  [1]: https://i.stack.imgur.com/HmaN9.png

</details>



huangapple
  • 本文由 发表于 2023年4月6日 23:24:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951201.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定