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

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

Spacing for multiple footnotes on one paragraph in r markdown

问题

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

这是一些示例代码:

  1. dat$place <- c("South Atlantic", "Gulf of Mexico", "Pacific")
  2. Footnotes.list$ft_IOModel <- "Footnote_1"
  3. Footnotes.list$ft_EFL <- "Footnote_2"
  4. Footnotes.list$ft_WFL <- "Footnote_3"
  5. for (i in 1:length(dat$place)) {
  6. rmarkdown::render(Comm_Region.Rmd,
  7. output_dir = output,
  8. output_file = paste0(filename,".docx"))
  9. }

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

  1. retailers.`r if(place == "South Atlantic") {
  2. paste0("^[",Footnotes.list$ft_IOModel,"] ^,^ ^[", Footnotes.list$ft_EFL,"]")}
  3. else if (place == "Gulf of Mexico") {
  4. paste0("^[",Footnotes.list$ft_IOModel,"] ^,^ ^[", Footnotes.list$ft_WFL,"]")}
  5. else {
  6. 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:

  1. dat$place &lt;- c(&quot;South Atlantic&quot;, &quot;Gulf of Mexico&quot;, &quot;Pacific&quot;)
  2. Footnotes.list$ft_IOModel &lt;- &quot;Footnote_1&quot;
  3. Footnotes.list$ft_EFL &lt;- &quot;Footnote_2&quot;
  4. Footnotes.list$ft_WFL &lt;- &quot;Footnote_3&quot;
  5. for (i in 1:length(dat$place)) {
  6. rmarkdown::render(Comm_Region.Rmd,
  7. output_dir = output,
  8. output_file = paste0(filename,&quot;.docx&quot;))
  9. }

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

  1. retailers.`r if(place == &quot;South Atlantic&quot;) {
  2. paste0(&quot;^[&quot;,Footnotes.list$ft_IOModel,&quot;] ^,^ ^[&quot;, Footnotes.list$ft_EFL,&quot;]&quot;)}
  3. else if (place == &quot;Gulf of Mexico&quot;) {
  4. paste0(&quot;^[&quot;,Footnotes.list$ft_IOModel,&quot;] ^,^ ^[&quot;, Footnotes.list$ft_WFL,&quot;]&quot;)}
  5. else {
  6. 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

  1. 如果您愿意在LaTeX中工作,可以使用`fnpct`包来帮助。
  2. ---
  3. title: "多个脚注"
  4. output: pdf_document
  5. header-includes:
  6. - \usepackage{fnpct}
  7. ---
  8. ```{r setup, include=FALSE}
  9. knitr::opts_chunk$set(echo = FALSE)
  1. place &lt;- "South Atlantic"
  2. Footnotes.list &lt;- list()
  3. Footnotes.list$ft_IOModel &lt;- "脚注 1"
  4. Footnotes.list$ft_EFL &lt;- "脚注 2"
  5. 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]
  2. [1]: https://i.stack.imgur.com/hajE6.png
英文:

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

  1. ---
  2. title: &quot;Multiple footnotes&quot;
  3. output: pdf_document
  4. header-includes:
  5. - \usepackage{fnpct}
  6. ---
  7. ```{r setup, include=FALSE}
  8. knitr::opts_chunk$set(echo = FALSE)
  9. ```
  10. ```{r footnotes, include=FALSE}
  11. place &lt;- &quot;South Atlantic&quot;
  12. Footnotes.list &lt;- list()
  13. Footnotes.list$ft_IOModel &lt;- &quot;Footnote 1&quot;
  14. Footnotes.list$ft_EFL &lt;- &quot;Footnote 2&quot;
  15. Footnotes.list$ft_WFL &lt;- &quot;Footnote 3&quot;
  16. ```
  17. Retailers.`r if(place == &quot;South Atlantic&quot;){
  18. paste0(&quot;\\footnote{&quot;, Footnotes.list$ft_IOModel, &quot;}\\footnote{&quot;, Footnotes.list$ft_EFL, &quot;}&quot;)
  19. }else if(place == &quot;Gulf of Mexico&quot;){
  20. paste0(&quot;\\footnote{&quot;, Footnotes.list$ft_IOModel, &quot;}\\footnote{&quot;, Footnotes.list$ft_WFL, &quot;}&quot;)
  21. }else{
  22. paste0(&quot;\\footnote{&quot;, Footnotes.list$ft_IOModel, &quot;}&quot;)
  23. }`

在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:

确定