Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left-align headers in Markdown table?

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?

like image 967
THE JOATMON Avatar asked Aug 14 '17 18:08

THE JOATMON


People also ask

How do you mark up a header row in a table?

Mark up the row and column header cells with <th> In all data tables, mark up each column and row header cell with the <th> tag. When a cell is essential to understand the data provided in the table, it must be marked up with <th> .

How do I center a table in markdown?

Tables are center-aligned by default when they are included in a table environment (i.e., when the table has a caption). If you do not want to center a table, use the argument centering = FALSE.

Can you indent a table in markdown?

Unfortunately markdown does not support this.


2 Answers

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.

like image 146
Waylan Avatar answered Oct 09 '22 12:10

Waylan



Markdown:

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

Result:

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

Note that the colon (":") on the second row, and the second character is what worked to The other option is to move the numbers to the left-most column (as below)

Amount | Items ------:|:-----     20 | Wooden Boards      5 | Old Parts 

Try it on StackEdit.

It does not seem to work putting the ---- line above the headers.

like image 27
yeOldeDataSmythe Avatar answered Oct 09 '22 12:10

yeOldeDataSmythe