如何修改R markdown生成的pdf文档中交叉引用的颜色?

发布于 2025-01-09 09:48:53 字数 1015 浏览 1 评论 0原文

---
title: "Annual Report"
author: "Xyz"
date: "`r format(Sys.time(),'%d %B, %Y')`"
output: 
  bookdown::pdf_document2:
    extra_dependencies: ["float"]
    number_sections: false
    toc: false
    linkcolor: blue

---


```{r, echo = FALSE}
library(ggplot2)
data(mtcars)
names(mtcars)
```
### Heading 1
```{r figure-1,echo=FALSE, fig.cap = "Sample Graph 1"}
ggplot(mtcars,aes(x=mpg,y=hp))+
  geom_point()+
  theme_classic()

```


To see another graph, please see figure \textcolor{blue}{\@ref(fig:figure-2)}

\newpage
### Heading 2
```{r figure-2,echo=FALSE, fig.cap = "Sample Graph 2"}
ggplot(mtcars,aes(x=mpg,y=carb))+
  geom_point()+
  theme_classic()

```


To see another graph, please see figure \@ref(fig:figure-1)

执行后,我在knitted pdf文档中的标题2之前发现了以下内容。

要查看另一张图,请参阅

代码中的图 refig:figure-2 refig:figure 也没有交叉引用。我想要的是我的文档应该在pdf文档中显示以下行:

要查看另一个图表,请参见图2

上述语句中的“2”应该是超链接,其颜色应该是蓝色,如果用户点击“2”,读者可以跳转到图 2。

---
title: "Annual Report"
author: "Xyz"
date: "`r format(Sys.time(),'%d %B, %Y')`"
output: 
  bookdown::pdf_document2:
    extra_dependencies: ["float"]
    number_sections: false
    toc: false
    linkcolor: blue

---


```{r, echo = FALSE}
library(ggplot2)
data(mtcars)
names(mtcars)
```
### Heading 1
```{r figure-1,echo=FALSE, fig.cap = "Sample Graph 1"}
ggplot(mtcars,aes(x=mpg,y=hp))+
  geom_point()+
  theme_classic()

```


To see another graph, please see figure \textcolor{blue}{\@ref(fig:figure-2)}

\newpage
### Heading 2
```{r figure-2,echo=FALSE, fig.cap = "Sample Graph 2"}
ggplot(mtcars,aes(x=mpg,y=carb))+
  geom_point()+
  theme_classic()

```


To see another graph, please see figure \@ref(fig:figure-1)

After execution, I found the following in knitted pdf document before Heading 2.

To see another graph, please see figure reffig:figure-2

reffig:figure in the code is not cross-referenced as well. What I want is that my document should show the following line in the pdf document:

To see another graph, please see figure 2

"2" in the above statement should be hyperlinked and its color should be blue, enabling the reader to jump to figure 2 if user clicks on "2".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2025-01-16 09:48:53

urlcolor:blue 添加到您的 yaml 应该可以工作。

---
title: "Annual Report"
author: "Xyz"
date: "`r format(Sys.time(),'%d %B, %Y')`"
output: 
  bookdown::pdf_document2:
    extra_dependencies: ["float"]
    number_sections: false
    toc: false
    linkcolor: blue

urlcolor: blue
---

原始答案在这里找到:R markdown 链接在编织为 pdf 时未格式化为蓝色

Adding urlcolor:blue to your yaml should work.

---
title: "Annual Report"
author: "Xyz"
date: "`r format(Sys.time(),'%d %B, %Y')`"
output: 
  bookdown::pdf_document2:
    extra_dependencies: ["float"]
    number_sections: false
    toc: false
    linkcolor: blue

urlcolor: blue
---

Original answer found here: R markdown link is not formatted blue when knitted to pdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文