如何在reStructuredText简单表中使列内容右对齐? [英] How to right-align columns content in reStructuredText simple tables?

查看:320
本文介绍了如何在reStructuredText简单表中使列内容右对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sphinx 编辑我的项目的文档,而该文件又使用了 reStructuredText 作为标记语言.

I'm editing the documentation for a project of mine using Sphinx, which in turn uses reStructuredText as markup language.

我有一个简单表(而不是 grid表),其中最右边的列报告包含我想右对齐的数字,但我不能找不到实现该目标的方法.

I have a simple table (as opposed to grid table) in which the rightmost column reports contains numbers that I would like to right-align, but I couldn't find how to achieve that.

============  =====================
Event               Score variation
============  =====================
Event 1                        +100
Event 2                         -25
Event 3                        -400
============  =====================

如果可以解决此问题,我很乐意切换到网格表.

I would be happy to switch to a grid table if this would allow me to solve the problem.

推荐答案

可悲的是,我不认为rst具有这种功能……表样式选项非常有限.就是说,如果要渲染为HTML,则可以添加带有css规则的自定义样式表,例如:

Sadly I don't think rst offers that ability... the table styling options are rather limited. That said, if you're rendering to HTML, you could add a custom stylesheet with a css rule such as:

table.right-align-right-col td:last-child {
    text-align: right
}

,然后添加指令:

.. rst-class:: right-align-right-col

在第一个文件中表格的右上方

.它笨重,但应该可以使用.

right above your table in the rst file. It's clunky, but it should work.

更新2013-2-6:从那时起,我需要自己完成此工作,并提出了一个更永久的解决方案. cloud_sptheme.ext.table_styling Sphinx扩展名添加了用于进行列对齐,每列css类以及其他表样式技巧的指令.尽管已打包为云" Sphinx主题的一部分,但它仍可与任何Sphinx主题一起使用.

update 2013-2-6: I've since needed to accomplish this myself, and came up with a more permanent solution. The cloud_sptheme.ext.table_styling Sphinx extension adds directives for doing column alignment, per-column css classes, and number of other table styling tricks. Despite being packaged as part of the "cloud" Sphinx theme, it should work with any Sphinx theme.

这篇关于如何在reStructuredText简单表中使列内容右对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆