markdown-tables

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Markdown Tables

Markdown 表格

Comprehensive guide to creating and formatting tables in markdown.
一份关于在Markdown中创建和格式化表格的全面指南。

Basic Table Syntax

基础表格语法

markdown
| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Cell 1   | Cell 2   | Cell 3   |
| Cell 4   | Cell 5   | Cell 6   |
Renders as:
Header 1Header 2Header 3
Cell 1Cell 2Cell 3
Cell 4Cell 5Cell 6
markdown
| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Cell 1   | Cell 2   | Cell 3   |
| Cell 4   | Cell 5   | Cell 6   |
渲染效果:
Header 1Header 2Header 3
Cell 1Cell 2Cell 3
Cell 4Cell 5Cell 6

Column Alignment

列对齐方式

markdown
| Left     | Center   | Right    |
|:---------|:--------:|---------:|
| Left     | Center   | Right    |
| aligned  | aligned  | aligned  |
Renders as:
LeftCenterRight
LeftCenteraligned
texttexttext
  • :---
    Left align (default)
  • :--:
    Center align
  • ---:
    Right align
markdown
| Left     | Center   | Right    |
|:---------|:--------:|---------:|
| Left     | Center   | Right    |
| aligned  | aligned  | aligned  |
渲染效果:
LeftCenterRight
LeftCenteraligned
texttexttext
  • :---
    左对齐(默认)
  • :--:
    居中对齐
  • ---:
    右对齐

Minimum Syntax

最简语法

The pipes and dashes don't need to align:
markdown
|Header|Header|
|-|-|
|Cell|Cell|
However, aligned tables are more readable in source.
管道符和短横线不需要对齐:
markdown
|Header|Header|
|-|-|
|Cell|Cell|
不过,对齐的表格在源码中更易读。

Escaping Pipe Characters

转义管道符

Use
\|
to include a literal pipe in a cell:
markdown
| Command | Description |
|---------|-------------|
| `a \| b` | Pipe operator |
| `cmd \|\| exit` | Or operator |
使用
\|
在单元格中包含字面意义的管道符:
markdown
| Command | Description |
|---------|-------------|
| `a \| b` | 管道运算符 |
| `cmd \|\| exit` | 或运算符 |

Inline Formatting in Tables

表格中的行内格式化

Tables support inline markdown:
markdown
| Feature | Syntax |
|---------|--------|
| **Bold** | `**text**` |
| *Italic* | `*text*` |
| `Code` | `` `code` `` |
| [Link](url) | `[text](url)` |
表格支持Markdown行内格式:
markdown
| Feature | Syntax |
|---------|--------|
| **Bold** | `**text**` |
| *Italic* | `*text*` |
| `Code` | `` `code` `` |
| [Link](url) | `[text](url)` |

Multi-line Cell Content

多行单元格内容

Standard markdown tables don't support multi-line cells. Workarounds:
标准Markdown表格不支持多行单元格。可以使用以下解决方法:

Using
<br>
Tags

使用
<br>
标签

markdown
| Step | Description |
|------|-------------|
| 1 | First line<br>Second line |
| 2 | Another step |
markdown
| Step | Description |
|------|-------------|
| 1 | 第一行<br>第二行 |
| 2 | 另一个步骤 |

Using HTML Tables

使用HTML表格

For complex layouts, use HTML:
html
<table>
  <tr>
    <th>Header</th>
    <th>Description</th>
  </tr>
  <tr>
    <td>Item</td>
    <td>
      <ul>
        <li>Point one</li>
        <li>Point two</li>
      </ul>
    </td>
  </tr>
</table>
对于复杂布局,使用HTML:
html
<table>
  <tr>
    <th>Header</th>
    <th>Description</th>
  </tr>
  <tr>
    <td>Item</td>
    <td>
      <ul>
        <li>Point one</li>
        <li>Point two</li>
      </ul>
    </td>
  </tr>
</table>

Empty Cells

空单元格

Use a space or leave empty:
markdown
| A | B | C |
|---|---|---|
| 1 |   | 3 |
| 4 | 5 |   |
使用空格或留空即可:
markdown
| A | B | C |
|---|---|---|
| 1 |   | 3 |
| 4 | 5 |   |

Wide Tables

宽表格

For tables with many columns, consider:
对于包含多列的表格,可以考虑:

Scrollable Container (HTML)

可滚动容器(HTML)

html
<div style="overflow-x: auto;">

| Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 |
|-------|-------|-------|-------|-------|-------|
| Data  | Data  | Data  | Data  | Data  | Data  |

</div>
html
<div style="overflow-x: auto;">

| Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 |
|-------|-------|-------|-------|-------|-------|
| Data  | Data  | Data  | Data  | Data  | Data  |

</div>

Vertical Layout

垂直布局

Transform wide tables into key-value pairs:
markdown
undefined
将宽表格转换为键值对形式:
markdown
undefined

Item 1

项目1

PropertyValue
NameFoo
TypeBar
StatusActive
undefined
PropertyValue
NameFoo
TypeBar
StatusActive
undefined

Common Table Patterns

常见表格模式

Comparison Table

对比表格

markdown
| Feature | Free | Pro | Enterprise |
|---------|:----:|:---:|:----------:|
| Users   | 5    | 50  | Unlimited  |
| Storage | 1GB  | 10GB| 100GB      |
| Support ||||
markdown
| Feature | Free | Pro | Enterprise |
|---------|:----:|:---:|:----------:|
| Users   | 5    | 50  | Unlimited  |
| Storage | 1GB  | 10GB| 100GB      |
| Support ||||

API Reference

API参考表格

markdown
| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `id`      | string || Unique identifier |
| `name`    | string || Display name |
| `limit`   | number || Max results (default: 10) |
markdown
| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `id`      | string || 唯一标识符 |
| `name`    | string || 显示名称 |
| `limit`   | number || 最大结果数(默认:10) |

Keyboard Shortcuts

键盘快捷键表格

markdown
| Action | Windows/Linux | macOS |
|--------|---------------|-------|
| Copy   | `Ctrl+C`      | `⌘+C` |
| Paste  | `Ctrl+V`      | `⌘+V` |
| Undo   | `Ctrl+Z`      | `⌘+Z` |
markdown
| Action | Windows/Linux | macOS |
|--------|---------------|-------|
| Copy   | `Ctrl+C`      | `⌘+C` |
| Paste  | `Ctrl+V`      | `⌘+V` |
| Undo   | `Ctrl+Z`      | `⌘+Z` |

Changelog

更新日志表格

markdown
| Version | Date | Changes |
|---------|------|---------|
| 2.0.0 | 2024-01-15 | Breaking: New API |
| 1.2.0 | 2024-01-01 | Added feature X |
| 1.1.0 | 2023-12-15 | Bug fixes |
markdown
| Version | Date | Changes |
|---------|------|---------|
| 2.0.0 | 2024-01-15 | 重大变更:全新API |
| 1.2.0 | 2024-01-01 | 新增功能X |
| 1.1.0 | 2023-12-15 | 修复Bug |

Best Practices

最佳实践

  1. Keep tables simple: If content is complex, consider alternatives
  2. Use consistent alignment: Align source pipes for readability
  3. Header row required: Always include a header row
  4. Escape special characters: Use
    \|
    for literal pipes
  5. Limit columns: Wide tables are hard to read
  6. Consider alternatives: Lists or definition lists may work better
  7. Test rendering: Tables render differently across platforms
  1. 保持表格简洁:如果内容复杂,考虑使用其他替代方案
  2. 使用一致的对齐方式:对齐源码中的管道符以提升可读性
  3. 必须包含表头行:始终添加表头行
  4. 转义特殊字符:使用
    \|
    表示字面意义的管道符
  5. 限制列数:宽表格可读性较差
  6. 考虑替代方案:列表或定义列表可能更合适
  7. 测试渲染效果:表格在不同平台的渲染效果可能不同

Markdownlint Rules for Tables

Markdownlint 表格规则

RuleDescription
MD055Table pipe style should be consistent
MD056Table column count should match header
MD058Tables should be surrounded by blank lines
RuleDescription
MD055表格管道符样式应保持一致
MD056表格列数应与表头一致
MD058表格前后应保留空行

Alternatives to Tables

表格的替代方案

Definition Lists (Some Parsers)

定义列表(部分解析器支持)

markdown
Term 1
: Definition 1

Term 2
: Definition 2
markdown
Term 1
: Definition 1

Term 2
: Definition 2

Bullet Lists with Bold Keys

带加粗键的项目符号列表

markdown
- **Name**: John Doe
- **Email**: john@example.com
- **Role**: Developer
markdown
- **Name**: John Doe
- **Email**: john@example.com
- **Role**: Developer

Nested Lists

嵌套列表

markdown
- Item 1
  - Property A: Value
  - Property B: Value
- Item 2
  - Property A: Value
  - Property B: Value
markdown
- Item 1
  - Property A: Value
  - Property B: Value
- Item 2
  - Property A: Value
  - Property B: Value