How to display Table in README.md file in Github?
Asked Answered
B

8

154

I want to display a table in readme.md file. I read GitHub Flavored Markdown and followed what it said. So this is my table:

| Attempt | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9 | #10 | #11 | #12 |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| Seconds | 301 | 283 | 290 | 286 | 289 | 285 | 287 | 287 | 272 | 276 | 269 | 254 |

However, I don't see any table and result looks like:

enter image description here

Bushmaster answered 7/9, 2016 at 19:52 Comment(1)
My experience (12/2021) suggests the documentation isn’t reliable with respect to .md files in a git repo., like the README.md file. I migrated about 300 .md files from Azure DevOps Wiki and most all tables came across and render just fine. That’s without the "preceding blank line" and without the "required" 3 hyphens (dashes). The few tables that did not render correctly were due to the column header line specifying more columns than the table contained. Azure DevOps Wiki engine didn’t mind. GitHub’s rendering did. Finding the source of the issue was painful. Fixing it was trivial.Tenpenny
G
202

You need to see documentation again. You can see this cheatsheet

In your case you need to make second line like in example below:

Attempt | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9 | #10 | #11
--- | --- | --- | --- |--- |--- |--- |--- |--- |--- |--- |---
Seconds | 301 | 283 | 290 | 286 | 289 | 285 | 287 | 287 | 272 | 276 | 269

difference between this code and your code in repo is that second line with separator has same columns as header. After that this table will be shown

Godesberg answered 7/9, 2016 at 20:21 Comment(2)
ya, thanks man. Even readme.md plugin on my Android studio still doesn't show the table while Github does. Thanks for sharing your knowledge.Bushmaster
@Bushmaster I recommend you to use some online Markdown editor. I used thisGodesberg
P
97
| Attempt | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9 | #10 | #11 | #12 |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| Seconds | 301 | 283 | 290 | 286 | 289 | 285 | 287 | 287 | 272 | 276 | 269 | 254 |

Making your example shorter to make easier to understand.

| Attempt | #1    | #2    |
| :---:   | :---: | :---: |
| Seconds | 301   | 283   |

And formatted to make it even easier to read.

| Attempt | #1    | #2    |
| :---:   | :---: | :---: |
| Seconds | 301   | 283   |

Headers must be separated by pipe | characters and underlined by - dash characters. There must be at least three hyphens in each column.

You can create tables by assembling a list of words and dividing them with hyphens - (for the first row), and then separating each column with a pipe |.

First Header  | Second Header
------------- | -------------
Content Cell  | Content Cell
Content Cell  | Content Cell

For aesthetic purposes, you can also add extra pipes on the ends:

| First Header  | Second Header |
| ------------- | ------------- |
| Content Cell  | Content Cell  |
| Content Cell  | Content Cell  |

GitHub Flavored Markdown

Our example becomes:

| Attempt | #1  | #2  |
| ------- | --- | --- |
| Seconds | 301 | 283 |

Finally, by including colons : within the header row, you can define text to be left-aligned, right-aligned, or center-aligned:

| Left-Aligned  | Center Aligned  | Right Aligned |
| :------------ |:---------------:| -----:|
| col 3 is      | some wordy text | $1600 |
| col 2 is      | centered        |   $12 |
| zebra stripes | are neat        |    $1 |

GitHub Flavored Markdown

So to center align, our example becomes:

| Attempt | #1    | #2    |
| :-----: | :---: | :---: |
| Seconds | 301   | 283   |
Patronage answered 12/9, 2016 at 3:7 Comment(2)
The final example is not correct because you need at least 3 hyphens as the documentation says.Seward
Great answer, thank you. I assume this must be marked as accepted.Catechumen
S
24

Don't forget to include an empty line before the table or it won't format correctly.

Speciosity answered 11/6, 2019 at 16:17 Comment(3)
This provide no useful answer , Please if you want to point to something you can use commentsSkijoring
This! This fixed my problem. The extra line is part of the formatting and I didn't realize that.Affliction
I am kind of impatient, I faced same problem, this resolved my problem as well.Carpenter
R
12

I use the Markdown Table tool (https://www.tablesgenerator.com/markdown_tables) that helps me to import data from csv or convert my html tables into Markdown which I can simply copy it into my README.md file and it's a real timesaver for me.

I generally write things that I'm going to publish on my README file on excel file and save it as csv and import into this tool and copy paste the Generated Markdown and it creates a table that its decent for others to read your instructions.

Hope that helps.

Russon answered 14/11, 2017 at 20:36 Comment(0)
Q
5

Save your readme file as README.md and not READ.ME

Quillan answered 7/9, 2016 at 20:3 Comment(1)
ah, sorry, it was my typo mistake (I fixed it in my question). It is readme.md actually. This is my repo github.com/Hesamedin/DatabaseTesterBushmaster
G
4
  • We can add three dashes (center aligned): | --- |
  • Center align with two dashes: | :---: |
  • Left align with two dashes: | :--- |
  • Right align with two dashes: | ---: |

Sample (Left align):

Collection coll = new ArrayList<>(); The ArrayList class implements the Collection interface.
coll = new TreeSet<>(); The TreeSet class also implements the Collection interface.
Graven answered 9/9, 2022 at 8:22 Comment(0)
C
3

| Header    | Heading |
| --------- | ------- |
| first     |         |
|           |         |
|           |         |
|           |         |
|           |         |
|           |         |
|           |         |

You can use this pattern to form README.md

Carbineer answered 26/5, 2023 at 12:14 Comment(0)
D
2

You can create tables with pipes | and hyphens -. Hyphens are used to create each column's header, while pipes separate each column. You must include a blank line before your table in order for it to correctly render

follow this image

First Header Second Header
Content Cell Content Cell
Content Cell Content Cell
Dorset answered 15/3, 2023 at 3:9 Comment(1)

© 2022 - 2025 — McMap. All rights reserved.