Reputation: 1800
Similar to the question asked here I am trying to insert anchors in a long document so that users can easily navigate to the TOC of the document.
My code is as follows:
---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
---
<a id="top"></a>
# First Section
Then I add [Go to Top](#top)
wherever I want a link to go to the top of the document.
The problem I am having is that on clicking Go to Top
, the page scrolls up such that First Section
is at the top, not the Table of Contents (which is what I want). So the users have to scroll up again to go to TOC.
Is there any way to scroll back to the very top of the document, so that TOC is seen again on the page.
I tried to to put <a id="top"></a>
before ---
, but that does not work.
Any help would be much appreciated!! Thanks.
Upvotes: 6
Views: 2649
Reputation: 11762
Just add you link somewhere and refers to #header
...
<a href="#header">back to top</a>
Upvotes: 5