首页 > 解决方案 > 如何在 R Markdown 中设置上一个/下一个按钮

问题描述

我能够使用 R markdown 成功设置目录。但是无法找到提供按钮以导航到上一页/下一页的方法。我希望它类似于此页面:https ://bookdown.org/yihui/rmarkdown/rmarkdown-site.html#site_navigation

我开始按照 rmarkdown 书的解释介绍一个目录。 https://bookdown.org/yihui/rmarkdown/pdf-document.html#table-of-contents-1 以下是我相应使用的 YAML 设置:

标题:“摘要报告”输出:html_document:toc:true toc_depth:2 number_sections:true df_print:分页toc_float:collapsed:true smooth_scroll:true

但是,这仍然不像原始链接中那样提供上一个/下一个按钮。想知道我是否缺少可以启用此功能的选项?

标签: htmlr-markdown

解决方案


以下是如何使用 HTML 在 R Markdown 中设置上一个/下一个按钮。

在我的示例中,我创建了四个标题:“上一个/下一个按钮”、“渲染文档”、“查找每个页面的参考”和“添加按钮”。它们将像这样链接:

我测试的第一页:href="#previousnext-button"

第二页:href="#render-document"

第三:href="#look-for-the-reference-for-each-page"

第四:href="#add-the-buttons"

它们以井号标签开头,后跟标题名称(井号标签和标题标题之间没有空格)。标题必须小写,用破折号连接,如下所示: "#the-name-of-the-heading-in-lowercase-separated-by-dashes . 如果标题中有斜杠,请忽略它,并将由斜杠分隔的两个单词键入为 one

按钮的一个示例如下所示:

<ul class="pager"> <!--this is the style of the button-->
<li><a href="#">Back to Summary</a></li> <!--This button takes me to the table of contents-->
<li><a href="#render-document">Next</a></li> <!--This button takes me to the previous page-->
</ul>

ul class="pager"这是按钮的样式。

href="#Your-heading-reference"将带您到链接的标题。

href="#"将带您回到目录。

这是我的测试图像:

在此处输入图像描述


推荐阅读