如何调整Jupyter Book右侧目录(Contents)的显示深度?
调整Jupyter Book右侧目录(Contents)的显示深度
要让右侧目录显示Jupyter Notebook里的所有标题层级,而非默认仅展示二级标题,可以通过两种方式配置:
方法一:全局统一设置(所有页面生效)
在项目根目录的_config.yml文件中添加或修改以下配置,指定目录要显示的最大标题层级(比如设置为6,覆盖Markdown/Notebook支持的所有标题层级):
html: toc: depth: 6
方法二:针对单个页面自定义设置
如果需要给不同页面配置不同的目录深度,可以修改_toc.yml,在对应文件条目下添加sections并指定depth参数:
format: jb-book root: index chapters: - file: 000_001_notebooks sections: - depth: 6 # 该页面下所有6级及以下标题都会显示在目录中 - file: 000_002_markdown sections: - depth: 6 - file: 000_003_markdown-notebooks sections: - depth: 6 - file: 001_000_print sections: - depth: 6 - file: 001_001_variables sections: - depth: 6 - file: 900_000_matplotlib sections: - depth: 6
配置完成后,重新构建你的Jupyter Book:
jupyter-book build .
这样右侧的Contents目录就会直接展开显示所有层级的标题,无需滚动才能查看深层内容。
内容的提问来源于stack exchange,提问作者John Goofy
相关产品推荐
相关产品推荐

