Left-align headers in Markdown table?

JOATMON picture JOATMON · Aug 14, 2017 · Viewed 20.2k times · Source

Using the table example from "Markdown Cheatsheet" on GitHub, you get this:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | $1600 |
| col 2 is      | centered      |   $12 |
| zebra stripes | are neat      |    $1 |

enter image description here

My question is, is there any way to left-align the header cells?

Answer

Waylan picture Waylan · Aug 14, 2017

It depends on which implementation you are using.

Tables are a non-standard feature of Markdown and each implementation which supports them does so differently. For example, the "cheetsheet" pointed to in the question is within the Markdown Here project. That project's Readme includes the following explanation:

To discover what can be done with Markdown in Markdown Here, check out the Markdown Here Cheatsheet and the other wiki pages.

So that "cheetsheet" is specific to the implementation used by Markdown Here.

GitHub has documented their implementation of Markdown as an extension of the Commonmark spec (Commonmark is a Markdown variant which does not support tables). According to example 192, the column headers receive the same alignment as the column cells:

| abc | defghi |
:-: | -----------:
bar | baz

<table>
<thead>
<tr>
<th align="center">abc</th>
<th align="right">defghi</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">bar</td>
<td align="right">baz</td>
</tr></tbody></table>

So, you need to check the specific implementation of Markdown you are using and read that implementation's documentation. However, personally, I have never come across an implementation which allows you to define separate alignment for the headers from the cells. In my experience, either you get headers which match the cells, or headers which have no alignment assigned.