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

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

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

问题

Consider the following RMarkdown document:

  1. ---
  2. output:
  3. pdf_document:
  4. number_sections: true
  5. fig_caption: yes
  6. title: 'Title'
  7. author:
  8. - Name
  9. geometry: margin=1in
  10. bibliography: references.bib
  11. csl: something.csl
  12. link-citations: yes
  13. linkcolor: blue
  14. urlcolor: black
  15. header-includes:
  16. \usepackage{setspace}
  17. \usepackage{graphicx}
  18. \usepackage[colorlinks]{hyperref}
  19. \usepackage[all]{hypcap}
  20. ---

Lorem ipsum [@reference]

  1. 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:

  1. ---
  2. output:
  3. pdf_document:
  4. number_sections: true
  5. fig_caption: yes
  6. title: 'Title'
  7. author:
  8. - Name
  9. geometry: margin=1in
  10. bibliography: references.bib
  11. csl: something.csl
  12. link-citations: yes
  13. linkcolor: blue
  14. urlcolor: black
  15. header-includes:
  16. \usepackage{setspace}
  17. \usepackage{graphicx}
  18. \usepackage[colorlinks]{hyperref}
  19. \usepackage[all]{hypcap}
  20. ---
  21. Lorem ipsum [@reference]
  22. ```{r landscape, echo=FALSE,include=TRUE,warning=FALSE,fig.cap="\\label{fig:landscape}Caption"}
  23. knitr::include_graphics("file.png")
  24. ```
  25. 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

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

  1. ---
  2. title: 'Title'
  3. output:
  4. pdf_document:
  5. number_sections: true
  6. fig_caption: yes
  7. author:
  8. - Name
  9. geometry: margin=1in
  10. bibliography: reference.bib
  11. link-citations: yes
  12. linkcolor: blue
  13. urlcolor: black
  14. header-includes:
  15. \newcommand\figref[1]{{\hypersetup{linkcolor=red}\autoref{#1}}}
  16. ---
  17. Lorem ipsum [@R-base]
  18. ```{r landscape, echo=FALSE, include=TRUE, warning=FALSE, fig.cap="\\label{fig:landscape}Caption"}
  19. plot(1:10)

引用至\figref{fig:landscape}.


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

  1. <details>
  2. <summary>英文:</summary>
  3. We can follow the technique described [here](https://tex.stackexchange.com/a/226374/261065) to define a new command for figure referencing.
  4. ~~~
  5. ---
  6. title: &#39;Title&#39;
  7. output:
  8. pdf_document:
  9. number_sections: true
  10. fig_caption: yes
  11. author:
  12. - Name
  13. geometry: margin=1in
  14. bibliography: reference.bib
  15. link-citations: yes
  16. linkcolor: blue
  17. urlcolor: black
  18. header-includes:
  19. \newcommand\figref[1]{{\hypersetup{linkcolor=red}\autoref{#1}}}
  20. ---
  21. Lorem ipsum [@R-base]
  22. ```{r landscape, echo=FALSE,include=TRUE,warning=FALSE,fig.cap=&quot;\\label{fig:landscape}Caption&quot;}
  23. plot(1:10)

Referencing to \figref{fig:landscape}.

  1. &lt;hr&gt;
  2. [![different color for figure reference][1]][1]
  3. [1]: https://i.stack.imgur.com/HmaN9.png
  4. </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:

确定