11.2. 使用既定主题#
正如入门指南中所述,下载 Sphinx 后,其安装包中即含有名为 themes
的文件夹, 包括 basic、alabaster、classic、sphinxdoc、scrolls、agogo、nature、pyramid、haiku、traditional、epub、bizstyle
等 12 种内置主题,此外还有不少第三方主题(例如 sphinx_rtd_theme
)可通过额外安装后使用。
这里我们主要介绍如何安装并使用 sphinx-rtd-theme 。
11.2.1. 安装主题模板#
直接进入命令行,输入 pip install sphinx-rtd-theme
,如下图所示:
完成以上步骤后,同学们可以在 python 的安装文件下找到 sphinx-rtd-theme文件夹。
在 sphinx_rtd_theme - theme.conf
文件中, 该主题的默认配置如下:
[theme]
inherit = basic
stylesheet = css/theme.css
pygments_style = default
[options]
canonical_url =
analytics_id =
collapse_navigation = True
sticky_navigation = True
navigation_depth = 4
includehidden = True
titles_only =
logo_only =
display_version = True
prev_next_buttons_location = bottom
style_external_links = False
style_nav_header_background =
基本选项含义:
inherit
给出了 “基本主题” 的名称。stylesheet
给出了将在 HTML 标头中引用的css文件的名称。pygments_style
给出了用于突出显示的Pygements 样式的名称。analytics_id
字符串。配置 Google Analytics ID 可以追踪网站访问情况。display_version
布尔值。配置是否显示版本号。collapse_navigation
布尔值。启用后,不在导航栏中显示 +。navigation_depth
整数。最大深度为4层,设置为 -1 表示不限制深度。
11.2.2. 修改配置文件:#
在 conf.py 中进行如下设置:
html_theme = 'sphinx_rtd_theme'
命令行中再次输入 make html
,即可生成相应主题的网页。