rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.86k stars 969 forks source link

Tabsets don't appear in ToC #1336

Open Romain-B opened 6 years ago

Romain-B commented 6 years ago

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

pat-s commented 5 years ago

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

toothpicky commented 5 years ago

Any solution to this?

ars17psu commented 4 years ago

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?

atusy commented 4 years ago

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}

Tab 1

Tab 1

subheader1

subheader2

Tab 2

Tab 2

subheader1

subheader2


![image](https://user-images.githubusercontent.com/30277794/68722441-cbf3c400-05f8-11ea-8241-1058e1045482.png)
cderv commented 4 years ago

@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.

atusy commented 4 years ago

@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.

cderv commented 4 years ago

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.

JeroenDMW commented 4 years ago

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

dschneiderch commented 4 years ago

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

atusy commented 3 years ago

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

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

atusy commented 3 years ago

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!

cderv commented 3 years ago

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 ! 👍

atusy commented 3 years ago

@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!!

januz commented 3 years ago

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

atusy commented 3 years ago

Sorry, I have no ideas...