在R Markdown中一个段落上的多个脚注的间距。

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

Spacing for multiple footnotes on one paragraph in r markdown

问题

这是一个相当简单的问题,应该有一个简单的解决方案,对吧?我一直在尝试删除脚注编号与文本之间的空格,我可能需要一些帮助。

这是一些示例代码:

dat$place <- c("South Atlantic", "Gulf of Mexico", "Pacific")
Footnotes.list$ft_IOModel <- "Footnote_1"
Footnotes.list$ft_EFL <- "Footnote_2"    
Footnotes.list$ft_WFL <- "Footnote_3"

for (i in 1:length(dat$place)) {
  rmarkdown::render(Comm_Region.Rmd, 
                    output_dir = output,
                    output_file = paste0(filename,".docx"))
}

这是 Comm_Region.Rmd 的 markdown 代码(关注 "South Atlantic" 和 "Gulf of Mexico" 的部分):

retailers.`r if(place == "South Atlantic") {
paste0("^[",Footnotes.list$ft_IOModel,"] ^,^ ^[", Footnotes.list$ft_EFL,"]")} 
else if (place == "Gulf of Mexico") {
paste0("^[",Footnotes.list$ft_IOModel,"] ^,^ ^[", Footnotes.list$ft_WFL,"]")} 
else {
paste0("^[",Footnotes.list$ft_IOModel,"]")}`

这是我想要的效果:在R Markdown中一个段落上的多个脚注的间距。

这是我一直得到的效果:
在R Markdown中一个段落上的多个脚注的间距。

我明白我需要删除逗号之前和之后的空格 ( ^,^ ^) 以获得所需的输出;然而,当我这样做时,整个代码会崩溃,脚注不再出现在页面底部。我也尝试过使用LaTex,但无济于事。肯定有更好的方法来编写这段代码。有任何建议吗?

英文:

This is a rather simple problem that should have a simple solution, right? I have been trying to remove the space between footnote numbers and I could use some help.

Here is some sample code:

dat$place &lt;- c(&quot;South Atlantic&quot;, &quot;Gulf of Mexico&quot;, &quot;Pacific&quot;)
Footnotes.list$ft_IOModel &lt;- &quot;Footnote_1&quot;
Footnotes.list$ft_EFL &lt;- &quot;Footnote_2&quot;    
Footnotes.list$ft_WFL &lt;- &quot;Footnote_3&quot;

for (i in 1:length(dat$place)) {
  rmarkdown::render(Comm_Region.Rmd, 
                    output_dir = output,
                    output_file = paste0(filename,&quot;.docx&quot;))
}

Here is the Comm_Region.Rmd markdown code (focusing on the code for "South Atlantic" and "Gulf of Mexico"):

retailers.`r if(place == &quot;South Atlantic&quot;) {
paste0(&quot;^[&quot;,Footnotes.list$ft_IOModel,&quot;] ^,^ ^[&quot;, Footnotes.list$ft_EFL,&quot;]&quot;)} 
else if (place == &quot;Gulf of Mexico&quot;) {
paste0(&quot;^[&quot;,Footnotes.list$ft_IOModel,&quot;] ^,^ ^[&quot;, Footnotes.list$ft_WFL,&quot;]&quot;)} 
else {
paste0(&quot;^[&quot;,Footnotes.list$ft_IOModel,&quot;]&quot;)}`

This is what I'm looking for: 在R Markdown中一个段落上的多个脚注的间距。

This is what I keep getting:
在R Markdown中一个段落上的多个脚注的间距。

I understand that I need to remove the spaces before and after the comma ( ^,^ ^) to get the desired output; however, when I do that the whole code breaks and the footnotes no longer appear at the bottom of the page. I've also tried LaTex but to no avail. There must be a better way to write this. Any suggestions?

答案1

得分: 1

如果您愿意在LaTeX中工作,可以使用`fnpct`包来帮助。

---
title: "多个脚注"
output: pdf_document  

header-includes:
  - \usepackage{fnpct}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)

place &lt;- "South Atlantic"
Footnotes.list &lt;- list()
Footnotes.list$ft_IOModel &lt;- "脚注 1"
Footnotes.list$ft_EFL &lt;- "脚注 2"
Footnotes.list$ft_WFL &lt;- "脚注 3"

零售商。r if(place == "South Atlantic"){ paste0("\\footnote{", Footnotes.list$ft_IOModel, "}\\footnote{", Footnotes.list$ft_EFL, "}") }else if(place == "Gulf of Mexico"){ paste0("\\footnote{", Footnotes.list$ft_IOModel, "}\\footnote{", Footnotes.list$ft_WFL, "}") }else{ paste0("\\footnote{", Footnotes.list$ft_IOModel, "}") }


[![在此输入图片说明][1]][1]

  [1]: https://i.stack.imgur.com/hajE6.png
英文:

If you are happy to work in LaTeX this may help using fnpct package.

---
title: &quot;Multiple footnotes&quot;
output: pdf_document  

header-includes:
  - \usepackage{fnpct}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```


```{r footnotes, include=FALSE}

place &lt;- &quot;South Atlantic&quot;
Footnotes.list &lt;- list()
Footnotes.list$ft_IOModel &lt;- &quot;Footnote 1&quot;
Footnotes.list$ft_EFL &lt;- &quot;Footnote 2&quot;
Footnotes.list$ft_WFL &lt;- &quot;Footnote 3&quot;

```



Retailers.`r if(place == &quot;South Atlantic&quot;){
   paste0(&quot;\\footnote{&quot;, Footnotes.list$ft_IOModel, &quot;}\\footnote{&quot;, Footnotes.list$ft_EFL, &quot;}&quot;)
 }else if(place == &quot;Gulf of Mexico&quot;){
    paste0(&quot;\\footnote{&quot;, Footnotes.list$ft_IOModel, &quot;}\\footnote{&quot;, Footnotes.list$ft_WFL, &quot;}&quot;)
    }else{
    paste0(&quot;\\footnote{&quot;, Footnotes.list$ft_IOModel, &quot;}&quot;)
 }`

在R Markdown中一个段落上的多个脚注的间距。

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

发表评论

匿名网友

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

确定