英文:
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
).
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}.
<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: '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)
Referencing to \figref{fig:landscape}.
<hr>
[![different color for figure reference][1]][1]
[1]: https://i.stack.imgur.com/HmaN9.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论