如何在 Rmarkdown 的 pdf 输出中的标题中添加链接

问题描述 投票:0回答:1

我正在尝试使用

rticles
包将我的 html 输出转换为 rmarkdown 中的 pdf 输出。我在
.Rmd
文件中更改了很多内容,除了我陷入困境的这一件事之外,一切都有效。我在 Rmarkdown 文件中有一个表格,其中有一个标题,其中有一个网站的链接作为脚注。该块不起作用,我收到错误。我已经尝试过在
caption
中获取文本引用,但这对我来说也不起作用(我猜是因为我没有使用
bookdown
)这是代码块:

X1=inflation_data$exp[!is.na(inflation_data$exp)&inflation_data$date<="2018-11-02"]-100
X2=inflation_data$exp[!is.na(inflation_data$exp)&inflation_data$date>="2019-01-01"]-100
Y1=inflation_data$inf_yy[inflation_data$date<="2018-11-02"]
Y2=inflation_data$inf_yy[inflation_data$date>="2019-01-01"]
df1<-DTW(X1,Y1)%>%setNames(c('x','Fixed ER regime'))
df2<-DTW(X2,Y2)%>%setNames(c('x','Managed ER regime'))
list_df=list(df1,df2)
df1122 <- list_df %>% reduce(inner_join, by='x')
colnames(df1122)[1]=''
knitr::kable(df1122,digits = 2, caption = 'Pan has been folRate regfixed) togram. Ogram was making ER flnto the IMF program.^[https://www.imf.org/05/12/pr19157-IF-Rhes-Sff-Lel-Ant-on-Emic-Poies-wh-Wn-for-a-Thee-Ye-EF]')%>%kable_classic("striped",font_size=10)%>%row_spec(0,bold=T)

我收到以下错误:

!缺少 $ 插入。 $ l.621 ...与巴基斯坦合作为期三年的 EFF]}

尝试在 elsevier.Rmd 中找到以下文本:
...与巴基斯坦合作为期三年]}

您可能需要在某个内联 R 表达式周围添加 $ $

r 
elsevier.Rmd(参见上面的提示)。看 https://github.com/rstudio/rmarkdown/issues/385了解更多信息。错误: LaTeX 无法编译 elsevier.tex。看 https://yihui.org/tinytex/r/#debugging 获取调试技巧。看 了解更多信息。执行停止

如果我从代码中删除

^[https://www.imf.org/05/12/pr19157-IF-Rhes-Sff-Lel-Ant-on-Emic-Poies-wh-Wn-for-a-Thee-Ye-EF]
,它可以正常工作,没有任何错误。

另外,YAML 部分:

---
title: "My title"
author:
  - name: My name            
    email: [email protected]        
    affiliation: My Department, My Company        
    correspondingauthor: true
    footnote: 1
address:
  - code: My department   
    organization: My organization
    addressline: 1 my adress
    city: My city   
    state: My state
    postcode: 14000
    country: My country
footnote:
  - code: 1
    text: "This is the first author footnote."
abstract: |
  This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. This is my long abstract. 
keywords: 
  - keyword1
  - keyword2
  - keyword3
journal: "An awesome journal"
date: "`r Sys.Date()`"
classoption: preprint, 3p, authoryear
bibliography: references.bib
linenumbers: false
numbersections: true
# Use a CSL with `citatssssssssssssssssssssssion_package = "default"`
# csl: https://www.zotero.org/styles/elsevier-harvard
output: 
  rticles::elsevier_article:
    latex_engine: xelatex
    keep_tex: true
    citation_package: natbib
fontsize: 12pt
---
pdf r-markdown bookdown rticles
1个回答
1
投票

请尝试提供您的 rmd 文件的一个可重现的小示例。通过我在下面所做的,我无法重现该错误。

---
output: pdf_document
---

```{r, echo=FALSE}
head(mtcars) |> 
    knitr::kable(caption = 'Pan has been folRate regfixed) togram. Ogram was making ER flnto the IMF program.^[https://www.imf.org/05/12/pr19157-IF-Rhes-Sff-Lel-Ant-on-Emic-Poies-wh-Wn-for a-Thee-Ye-EF]')
```

这让我觉得这不是 Rmarkdown 的问题。我的猜测是 LaTeX 上的

^
符号或网址中的空格存在问题:

Wn-for a-Thee-Ye-EF]
      ^
      ^
     here

更新您的 LaTeX 解析器可能会有所帮助。另外,您可以将空格编码为

%20
,如下所示:编码空格字符的 URL:+ 或 %20?

© www.soinside.com 2019 - 2024. All rights reserved.