如何用狮身人面像制作2列
我想在我的文档中创建多个列。
在全球范围内,我想做一些类似于 此主页 的事情,其中有 3 列:一列带有当前版本,其中包含新闻和内容更新和基础知识。
当我在谷歌上搜索有关 Sphinx 中的多列时,我发现将列表分成两列,这不是我的情况
在维基上我发现的多列的唯一内容是表格,但我认为这不适用于此处?
在使用 Sphinx 的第一个文件中这可能吗?
多谢
I want to make multiple columns on my documentation.
Globally, i would like to do something similar as this homepage, where there is 3 columns : one with current release, one with news & updates, and Basics.
When i search on google about multiple columns in Sphinx, i found about splitting a list in 2 columns which is not my case
On the wiki the only things i found with multiple columns is the table, but i don't think this can apply here ?
Is this possible in rst files using Sphinx ?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
好吧,我终于找到了:
您可以在 sphinx/rst 文件中使用
container
关键字来分隔内容然后在您的 .css 文件中:
使用此方法,您可以在容器中写入您想要的所有内容(图像,链接、文本……它将正确显示。
Ok i finally found it :
you can use
container
keyword in sphinx/rst files to separate thingsAnd then in your .css file :
With this method, you can write everything you want in the container (image, links, text, ... and it will be displayed properly.
这是一个有点老的问题,但现在这个问题的一个可能更好的答案是使用 https://sphinx-panels.readthedocs.io/en/latest/
该扩展提供了您在普通休息中没有的各种组件。
This is a bit of an old question, but a potentially better answer to this question nowadays is to use https://sphinx-panels.readthedocs.io/en/latest/
That extension provides various components that you don't have in plain reST.
一种解决方案是使用 sphinx-design 扩展,它是面板的后继者。重要的是,这不需要您配置任何 html 或 css。
One solution is to use the sphinx-design extension which is the successor to panels. Importantly, this does not require you to configure any html or css.
有几种方法可以做到这一点,因此您可以找到一个基于三列的 sphinx 主题(据我所知没有),或者作为 @Steve_Piercy 建议您可以创建自己的主题,这可能是一项艰巨的任务。但是,您可以使用选择的主题,只需调整
.rst
文件内容并覆盖您的主题即可以 3 列的方式显示内容。为此,您需要一些 HTML 和 CSS。因此,首先您需要创建一个
test.rst
,其中的内容为 html 原始代码,如下所示:现在内容已准备就绪,我们在
_static/custom_style 下为其创建一个样式文件。 css
包含以下代码:最后一步是将此样式添加到您的
conf.py
文件中,以便将其添加到您的主题中。因此,在您的conf.py
中添加以下行:就是这样,现在运行并测试。输出应该看起来像这样(取决于您的主题):

There are a couple of ways to do this, so either you find a three-columns-based sphinx theme (not that I know of any) or as @Steve_Piercy suggested you can create your own theme, which will probably be quite the task. However, you can instead use a theme of choice and simply adjust your
.rst
file content and overwrite your theme to display your content in 3 columns fashion. To do that you need some HTML and CSS though.So first you need to create a
test.rst
with your content as html raw code like the following:Now that the content is ready, we create a style file for it under
_static/custom_style.css
that includes the following code:The last step is to add this style to your
conf.py
file in order for it to be added it to your theme. So in yourconf.py
add the following lines:That's it, now run and test. The output should look somewhat like this (depending on your theme):

我不允许向 LudwigVonKoopa 接受的解决方案添加评论,但存在如何结束两列设置的问题。
除了已接受的解决方案之外,根据 SuperKogito 的答案,我将其添加到我的 css 文件中:
这允许使用以下内容结束两列部分
。这不会在 html 输出中生成一行,但它会结束两列部分。
I am not allowed to add a comment to the accepted solution from LudwigVonKoopa but there is the question how to end the two column setting.
Additionally to the accepted solution and based on the answer from SuperKogito, I added this to my css file:
This allows to end the two column part with
This does not generate a line in the html output but it ends the two column part.