Markdown 表格怎么写:从入门到对齐
Markdown 表格靠“管道符 |”和“分隔行”两样东西就能画出来。本文把写法、对齐和几个容易踩的坑一次讲透。
Markdown 表格怎麼寫:從入門到對齊
Markdown 表格靠「管線符 |」和「分隔行」兩樣東西就能畫出來。本文把寫法、對齊和幾個容易踩的坑一次講透。
How to Write Markdown Tables: From Basics to Alignment
A Markdown table is drawn with just two things: the "pipe |" and the "separator row". This article covers the syntax, alignment, and a few common pitfalls in one go.
一、最基础的表格写法
一张表由表头行、分隔行和内容行组成,列与列之间用 | 隔开:
| 功能 | 快捷键 | 说明 |
| --- | --- | --- |
| 加粗 | Ctrl+B | 常用格式 |
| 链接 | Ctrl+K | 插入网址 |
渲染结果:
| 功能 | 快捷键 | 说明 |
|---|---|---|
| 加粗 | Ctrl+B | 常用格式 |
| 链接 | Ctrl+K | 插入网址 |
记住:分隔行里的 --- 至少要三个减号,它决定哪一列是“对齐设置”,内容随便填几行都行。
二、左、中、右三种对齐
对齐方式写在分隔行里,靠冒号 : 的位置决定:
| 写法 | 对齐 |
|---|---|
:--- | 左对齐(默认) |
:---: | 居中 |
---: | 右对齐(数字常用) |
例如金额右对齐、表头居中:
| 项目 | 金额(元) |
| :--- | ---: |
| 咖啡 | 28 |
| 键盘 | 399 |
三、单元格内换行与竖线转义
单元格里想换行
在单元格内用 HTML 的 <br> 强制换行即可:
| 地点 | 备注 |
| --- | --- |
| 北京 | 总部<br>研发中心 |
内容里本身有竖线 |
用反斜杠转义:\|,否则会被当成列分隔符。
| 表达式 | 含义 |
| --- | --- |
| a \| b | 按位或 |
四、让编辑器替你画表
手写管道符容易数错列数。在 365Lab 编辑器 里:
- 点顶栏“插入表格”,拖选行列数,自动生成骨架;
- 表格内回车自动补一行,末格按
Tab追加新行; - 命令面板还能“在下方插入行 / 删除当前列”,表头受保护不会被误删。
更系统的功能说明见 使用指南 · 表格章节。
五、常见问题
Q:分隔行能不能省略?
A:不能。没有 --- 分隔行,Markdown 不会把它当表格,只会显示成普通文字。
Q:每行列数不一致会怎样?
A:渲染器通常会按表头列数补空,但建议保持一致,避免错位。
Q:表格太长怎么办?
A:窄屏上表格会横向滚动;转 PDF 前尽量精简列,详见 Markdown 转 PDF。
回到基础,先看看 Markdown 是什么,把整体语法串起来。
一、最基礎的表格寫法
一張表由表頭列、分隔行和內容列組成,列與列之間用 | 隔開:
| 功能 | 快捷鍵 | 說明 |
| --- | --- | --- |
| 加粗 | Ctrl+B | 常用格式 |
| 連結 | Ctrl+K | 插入網址 |
渲染結果:
| 功能 | 快捷鍵 | 說明 |
|---|---|---|
| 加粗 | Ctrl+B | 常用格式 |
| 連結 | Ctrl+K | 插入網址 |
記住:分隔行裡的 --- 至少要三個減號,它決定哪一列是「對齊設定」,內容隨便填幾行都行。
二、左、中、右三種對齊
對齊方式寫在分隔行裡,靠冒號 : 的位置決定:
| 寫法 | 對齊 |
|---|---|
:--- | 左對齊(預設) |
:---: | 居中 |
---: | 右對齊(數字常用) |
例如金額右對齊、表頭居中:
| 項目 | 金額(元) |
| :--- | ---: |
| 咖啡 | 28 |
| 鍵盤 | 399 |
三、儲存格內換行與豎線轉義
儲存格裡想換行
在儲存格內用 HTML 的 <br> 強制換行即可:
| 地點 | 備註 |
| --- | --- |
| 北京 | 總部<br>研發中心 |
內容裡本身有豎線 |
用反斜線轉義:\|,否則會被當成列分隔符。
| 運算式 | 含義 |
| --- | --- |
| a \| b | 位元或 |
四、讓編輯器替你畫表
手寫管線符容易數錯列數。在 365Lab 編輯器 裡:
- 點頂欄「插入表格」,拖選行列數,自動生成骨架;
- 表格內回車自動補一行,末格按
Tab追加新行; - 命令面板還能「在下方插入列 / 刪除目前列」,表頭受保護不會被誤刪。
更系統的功能說明見 使用指南 · 表格章節。
五、常見問題
Q:分隔行能不能省略?
A:不能。沒有 --- 分隔行,Markdown 不會把它當表格,只會顯示成普通文字。
Q:每行列數不一致會怎樣?
A:渲染器通常會按表頭列數補空,但建議保持一致,避免錯位。
Q:表格太長怎麼辦?
A:窄屏上表格會橫向滾動;轉 PDF 前盡量精簡欄,詳見 Markdown 轉 PDF。
回到基礎,先看看 Markdown 是什麼,把整體語法串起來。
1. The most basic table syntax
A table is made of a header row, a separator row, and content rows, with columns separated by |:
| Feature | Shortcut | Description |
| --- | --- | --- |
| Bold | Ctrl+B | Common format |
| Link | Ctrl+K | Insert URL |
Rendered result:
| Feature | Shortcut | Description |
|---|---|---|
| Bold | Ctrl+B | Common format |
| Link | Ctrl+K | Insert URL |
Remember: The --- in the separator row needs at least three hyphens; it decides which column holds the "alignment setting", and the content rows can be whatever.
2. Left, center, and right alignment
Alignment is written in the separator row, decided by where the colon : sits:
| Syntax | Alignment |
|---|---|
:--- | Left (default) |
:---: | Center |
---: | Right (common for numbers) |
For example, right-align amounts and center the header:
| Item | Amount (¥) |
| :--- | ---: |
| Coffee | 28 |
| Keyboard | 399 |
3. Line breaks inside cells and escaping the pipe
Breaking a line inside a cell
Use HTML's <br> inside the cell to force a line break:
| Place | Note |
| --- | --- |
| Beijing | HQ<br>R&D center |
When the content itself contains a pipe |
Escape it with a backslash: \|, otherwise it's treated as a column separator.
| Expression | Meaning |
| --- | --- |
| a \| b | Bitwise OR |
4. Let the editor draw the table for you
Hand-writing pipes makes it easy to miscount columns. In the 365Lab editor:
- Click "Insert table" in the top bar, drag to pick rows and columns, and a skeleton is generated automatically;
- Press Enter inside the table to auto-add a row; in the last cell, Tab appends a new row;
- The command palette can also "insert row below / delete current column", and the header is protected from accidental deletion.
For a more systematic feature guide, see the User Guide · Tables section.
5. FAQ
Q: Can the separator row be omitted?
A: No. Without the --- separator row, Markdown won't treat it as a table—it just shows as plain text.
Q: What if rows have different column counts?
A: Renderers usually pad to the header's column count, but keep them consistent to avoid misalignment.
Q: What if the table is too long?
A: On narrow screens the table scrolls horizontally; before converting to PDF, trim columns—see Markdown to PDF.
To go back to basics, first read What Is Markdown to tie the whole syntax together.