kbits-theme-demo Demonstration of kbits-theme for Pelican
Atom · RSS

Table Styles and Alignment in Markdown

The table styles that kbits-theme supports for reStructuredText tables can also be applied to tables in Markdown documents, but it takes some extra work. You might expect to be able to attach classes to tables with the attribute list extension, but unfortunately, the syntax does not work with tables, and the author of the Python Markdown package has no interest in fixing this (see this issue). Instead, if you want to create a table with a class in Markdown, you have to write out the table in HTML.

So, if you want to create a table with the "booktabs" class, you have to write out:

<table class="booktabs">
    <thead>
        <!-- The header row needs to be placed in a thead so that the body rows
        are shaded appropriately. -->
        <tr>
            <th>Color</th>
            <th>Element</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Blue</td>
            <td>Water</td>
        </tr>
        <tr>
            <td>Green</td>
            <td>Earth</td>
        </tr>
        <tr>
            <td>Red</td>
            <td>Fire</td>
        </tr>
        <tr>
            <td>Yellow</td>
            <td>Air</td>
        </tr>
    </tbody>
</table>

and that gets you:

Color Element
Blue Water
Green Earth
Red Fire
Yellow Air

Changing the class to "borderless" gives you:

Color Element
Blue Water
Green Earth
Red Fire
Yellow Air

There are also classes for aligning tables: align-left, align-center and align-right. Let's see align-center:

Color Element
Blue Water
Green Earth
Red Fire
Yellow Air

Let's combine a border style with an alignment — class="booktabs align-left":

Color Element
Blue Water
Green Earth
Red Fire
Yellow Air

I think you can take it from here.