简体   繁体   English

交叉引用不适用于rmarkdown beamer演示文稿

[英]Cross-referencing not working in rmarkdown beamer presentation

I would like to link section headers in a beamer_presentation via Rmarkdown (ie., creating cross-references or Pandoc's internal links ). 我想通过Rmarkdown链接beamer_presentation中的节头(即,创建交叉引用或Pandoc的内部链接 )。 For example, I would like to have a link such as "see 'introduction'", by clicking this link, the presentation should jump to slide with the title 'introduction'. 例如,我希望有一个链接,例如“看'''',通过点击此链接,演示文稿应跳转到标题为”简介“的幻灯片。

I have tried this code: 我试过这段代码:

---
output: beamer_presentation
---

## TOC

- [Important](#Important)
- [More](#More)
- [Stuff](#stuff)



## Important

jklödfs

## More


sdfjkls

## stuff {#stuff}

However, the expected behavior does not show up. 但是,预期的行为不会显示出来。 Instead, if the link is clicked, the first pages is shown (but not the respective slide). 相反,如果单击链接,则会显示第一页(但不会显示相应的幻灯片)。


SessionInfo: SessionInfo:

pandoc 1.19.1 pandoc 1.19.1

R version 3.4.0 (2017-04-21) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Sierra 10.12.5 R版本3.4.0(2017-04-21)平台:x86_64-apple-darwin15.6.0(64位)运行于:macOS Sierra 10.12.5

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib Matrix产品:默认BLAS:/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK:/Library/Frameworks/R.framework/Versions/3.4/Resources /lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 locale:[1] en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base 附加基础包:[1] stats graphics grDevices utils数据集方法库

loaded via a namespace (and not attached): [1] compiler_3.4.0 backports_1.1.0 magrittr_1.5 rsconnect_0.8 rprojroot_1.2 htmltools_0.3.6 tools_3.4.0 yaml_2.1.14 Rcpp_0.12.11 通过命名空间加载(而不是附加):[1] compiler_3.4.0 backports_1.1.0 magrittr_1.5 rsconnect_0.8 rprojroot_1.2 htmltools_0.3.6 tools_3.4.0 yaml_2.1.14 Rcpp_0.12.11
[10] stringi_1.1.5 rmarkdown_1.5 knitr_1.16 stringr_1.2.0 digest_0.6.12 evaluate_0.10 [10] stringi_1.1.5 rmarkdown_1.5 knitr_1.16 stringr_1.2.0 digest_0.6.12 evaluate_0.10

Edit: 编辑:

According to an issue on GitHub : 根据GitHub上的一个问题

It seems that slide uses the fragment identifier (the part after the hash in the URL) to keep track of which slide you're on, so all internal links generated by pandoc won't work. 幻灯片似乎使用片段标识符(URL中的散列后面的部分)来跟踪您所在的幻灯片,因此pandoc生成的所有内部链接都不起作用。

However, yhou can always write your own links liek link where 1 is the slide number you want to link to... 但是,yhou总是可以写自己的链接liek链接,其中1是你要链接的幻灯片编号...

So you have to use the following workaround (in principle same as my old one below, but directly in the Rmd file): 因此,您必须使用以下解决方法(原则上与下面的旧解决方案相同,但直接在Rmd文件中):

---
title: "Untitled"
author: "John Doe"
date: "13 June 2017"
output:
  slidy_presentation: default
  ioslides_presentation: default
  beamer_presentation: default
---

## TOC

[Important](#(3))

[More](#(4))

[Stuff](#(5))

## Important {#important}

jklödfs

## More {#more}

sdfjkls

## stuff {#stuff}

Old answer below: 老答案如下:

I am afraid this is just a workaround, but a working one (at least on my system, Win 8.1, R 3.4.0, pandoc 1.19.2.1, knitr 1.15.16): 我担心这只是一种解决方法,但是一种工作方式(至少在我的系统上,Win 8.1,R 3.4.0,pandoc 1.19.2.1,knitr 1.15.16):

Using the Rmd doc below: 使用下面的Rmd文档:

---
title: "Untitled"
author: "John Doe"
date: "13 June 2017"
output:
  slidy_presentation: default
  ioslides_presentation: default
  beamer_presentation: default
---

## TOC

[Important](#important)

[More](#more)

[Stuff](#stuff)

## Important {#important}

jklödfs

## More {#more}

sdfjkls

## stuff {#stuff}

Run Knit to html (works for both ioslides and slidy) and find and change the TOC section: 运行Knit到html(适用于ioslides和slidy)并查找和更改TOC部分:

<div id="toc" class="slide section level2">
<h2>TOC</h2>
<p><a href="#important">Important</a></p>
<p><a href="#more">More</a></p>
<p><a href="#stuff">Stuff</a></p>
</div>

to this: 对此:

<div id="toc" class="slide section level2">
<h2>TOC</h2>
<p><a href="#(3)">Important</a></p>
<p><a href="#(4)">More</a></p>
<p><a href="#(5)">Stuff</a></p>
</div>

The issue is browser cannot find eg the #important section, but finds #(3) . 问题是浏览器找不到例如#important部分,但发现#(3) I do not know why unfortunately as the produced html file have sections <div id="important" class="slide section level2"> etc. 我不知道为什么不幸的是因为生成的html文件有<div id="important" class="slide section level2">等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM