rmarkdown icon indicating copy to clipboard operation
rmarkdown copied to clipboard

Tabsets don't appear in ToC

Open Romain-B opened this issue 6 years ago • 15 comments

It appears that when headers are put in tabset format, they don't appear in the table of contents. Even stranger : when there are subheaders inside the tabsets, these will appear in the toc, but there will be no separation or distinction between the subheaders of different tabs

---
title: Hello World
output: 
  html_document:
    toc: TRUE
    toc_float: true
    toc_depth: 4
---

# My header {.tabset}

## Tab 1
### subheader1
### subheader2

## Tab 2

### subheader1
### subheader2

image

Romain-B avatar May 09 '18 14:05 Romain-B

Just came across this. Making sure it doesn't get forgotten :rocket:

pat-s avatar May 09 '19 08:05 pat-s

Any solution to this?

toothpicky avatar Aug 20 '19 18:08 toothpicky

I am using rmarkdown v1.16 and knitr v1.25. I am experiencing the same behavior as the above reported question. Have there been any updates to this?

ars17psu avatar Nov 12 '19 19:11 ars17psu

Here's a tricky workaround

---
title: Hello World
output: 
  html_document:
    toc: TRUE
    toc_float: true
    toc_depth: 4
---

```{css}
.tabset h2 {display: none;}
```

# My header  {.tabset}

<h2>Tab 1</h2>

## Tab 1

### subheader1

### subheader2

<h2>Tab 2</h2>

## Tab 2

### subheader1

### subheader2

image

atusy avatar Nov 13 '19 00:11 atusy

@atusy this is great ! However, tabpanel is trickier as I don't think the toc will allow to navigate in the headers that are inside the tabbed panel. In my case it doesn't. Does it work for you ? I think it would need to activate the correct tab (show) when one of the header in the panel is clicked. I am looking into JS to see if this is possible - that would complete your trick I guess. From what I saw up to now, it is not so easy to get the TOC to work with tabbed content.

cderv avatar Nov 13 '19 07:11 cderv

@cderv You are right. My trick just shows ToC whose links are out of order. We need one (?) more trick by JS! Thanks for your help.

atusy avatar Nov 13 '19 08:11 atusy

I also think this should be looked into after #1260 when bootstrap upgrade is done because it will change some things. Maybe bs4 will also help with this.

cderv avatar Nov 13 '19 08:11 cderv

found this: https://stackoverflow.com/questions/54803465/rmarkdown-is-it-possible-to-display-the-toc-of-the-current-tab-only-in-a-tabse

JeroenDMW avatar Feb 02 '20 22:02 JeroenDMW

the stackoverflow link didn't work for me so i'm definitely still waiting for a solution for this! the previous sort-of workaround without navigation is better than nothing though so thanks @atusy

dschneiderch avatar May 07 '20 01:05 dschneiderch

I made some hacks. With files below, you can navigate to tabsets from floating ToC.

https://gist.github.com/atusy/4b076cc084d9e920b34d6d25f85e5176

atusy avatar Jan 10 '21 04:01 atusy

I think the above trick needs lots more improvements which is still difficult for me.

Alternatively, I implemented the feature in minidown::mini_document. Install it with remotes::install_github("atusy/minidown") and follow the directions at

https://minidown.atusy.net/#tabset

Feed backs are welcome!

atusy avatar Jan 14 '21 00:01 atusy

I think the above trick needs lots more improvements which is still difficult for me.

What are the improvement to be made ? What makes it more difficult to support here than in minidown ? Do you want to discuss it in a PR ? (as if we were not already late on your previous ones 😅 )

Great package by the way ! There are a lot of great feature in your mini_document ! It is a really nice addition to the ecosystem ! 👍

cderv avatar Jan 14 '21 10:01 cderv

@cderv

Tow major difficulties are:

  1. Navigation to the hidden tab from the ToC requires clicking twice. I tried anchor.click(); anchor.click();, but no luck.
  2. Navigation to tabs when their name are not unique. Current implementation navigates to the last tab.

Anyway, let's draft and discuss the PR.

Great package by the way ! There are a lot of great feature in your mini_document ! It is a really nice addition to the ecosystem ! :+1:

Thanks a lot! I'm so glad to hear it!!

atusy avatar Jan 14 '21 13:01 atusy

Is it likely that this feature will be implemented? I have a template that builds on bookdown::html_document2() and would like to avoid trying to rewrite it using minidown :)

januz avatar Apr 18 '21 18:04 januz

Sorry, I have no ideas...

atusy avatar Apr 18 '21 21:04 atusy