主页 Markdown Table Syntax
Post
Cancel

Markdown Table Syntax

Preface

I used to always fail to insert tables in markdown. This post shares how to insert tables in markdown.

demo:

  • Plain style
1
2
3
4
5
| 一个普通标题 | 一个普通标题 | 一个普通标题 |
| ------| ------ | ------ |
| 短文本 | 中等文本 | 稍微长一点的文本 |
| 稍微长一点的文本 | 短文本 | 中等文本 |

The rendered result looks like this

A plain headerA plain headerA plain header
Short textMedium textSlightly longer text
Slightly longer textShort textMedium text

Alignment

1
2
3
4
5
| 左对齐标题 | 右对齐标题 | 居中对齐标题 |
| :------| ------: | :------: |
| 短文本 | 中等文本 | 稍微长一点的文本 |
| 稍微长一点的文本 | 短文本 | 中等文本 |

The result looks like this

Left-aligned headerRight-aligned headerCentered header
Short textMedium textSlightly longer text
Slightly longer textShort textMedium text

Syntax notes:

  • Extra spaces between |, -, :, are ignored and do not affect the layout.
  • By default the header row is centered, and the content is left-aligned.
  • -: means the content and the header are right-aligned.
  • :- means the content and the header are left-aligned.
  • :-: means the content and the header are centered.
  • Extra spaces between content and | are ignored.
  • The first | and the last | on each line can be omitted.
  • There must be at least one -.

I always forget how to write a markdown table.

If you need to add a column, you can copy and paste the | from the previous row and the |:-----:| from the row below.

I use the open-source, free MacDown. Feel free to download it — I use it for publishing articles.

End of article

该博客文章由作者通过 CC BY 4.0 进行授权。