markdown-tables
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMarkdown 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 1 | Header 2 | Header 3 |
|---|---|---|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |
markdown
| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |渲染效果:
| Header 1 | Header 2 | Header 3 |
|---|---|---|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |
Column Alignment
列对齐方式
markdown
| Left | Center | Right |
|:---------|:--------:|---------:|
| Left | Center | Right |
| aligned | aligned | aligned |Renders as:
| Left | Center | Right |
|---|---|---|
| Left | Center | aligned |
| text | text | text |
- Left align (default)
:--- - Center align
:--: - Right align
---:
markdown
| Left | Center | Right |
|:---------|:--------:|---------:|
| Left | Center | Right |
| aligned | aligned | aligned |渲染效果:
| Left | Center | Right |
|---|---|---|
| Left | Center | aligned |
| text | text | text |
- 左对齐(默认)
:--- - 居中对齐
:--: - 右对齐
---:
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>使用 <br>
标签
<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
undefinedItem 1
项目1
| Property | Value |
|---|---|
| Name | Foo |
| Type | Bar |
| Status | Active |
undefined| Property | Value |
|---|---|
| Name | Foo |
| Type | Bar |
| Status | Active |
undefinedCommon 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
最佳实践
- Keep tables simple: If content is complex, consider alternatives
- Use consistent alignment: Align source pipes for readability
- Header row required: Always include a header row
- Escape special characters: Use for literal pipes
\| - Limit columns: Wide tables are hard to read
- Consider alternatives: Lists or definition lists may work better
- Test rendering: Tables render differently across platforms
- 保持表格简洁:如果内容复杂,考虑使用其他替代方案
- 使用一致的对齐方式:对齐源码中的管道符以提升可读性
- 必须包含表头行:始终添加表头行
- 转义特殊字符:使用 表示字面意义的管道符
\| - 限制列数:宽表格可读性较差
- 考虑替代方案:列表或定义列表可能更合适
- 测试渲染效果:表格在不同平台的渲染效果可能不同
Markdownlint Rules for Tables
Markdownlint 表格规则
| Rule | Description |
|---|---|
| MD055 | Table pipe style should be consistent |
| MD056 | Table column count should match header |
| MD058 | Tables should be surrounded by blank lines |
| Rule | Description |
|---|---|
| MD055 | 表格管道符样式应保持一致 |
| MD056 | 表格列数应与表头一致 |
| MD058 | 表格前后应保留空行 |
Alternatives to Tables
表格的替代方案
Definition Lists (Some Parsers)
定义列表(部分解析器支持)
markdown
Term 1
: Definition 1
Term 2
: Definition 2markdown
Term 1
: Definition 1
Term 2
: Definition 2Bullet Lists with Bold Keys
带加粗键的项目符号列表
markdown
- **Name**: John Doe
- **Email**: john@example.com
- **Role**: Developermarkdown
- **Name**: John Doe
- **Email**: john@example.com
- **Role**: DeveloperNested Lists
嵌套列表
markdown
- Item 1
- Property A: Value
- Property B: Value
- Item 2
- Property A: Value
- Property B: Valuemarkdown
- Item 1
- Property A: Value
- Property B: Value
- Item 2
- Property A: Value
- Property B: Value