# 使用表格组织信息

您可以创建表格来组织评论、议题、拉取请求和 wiki 中的信息。

## 创建表

可以使用竖线 `|` 和连字符 `-` 创建表。 连字符用于创建每列的标题，而竖线用于分隔每列。 必须在表格前包含空白链接，以便其正确呈现。

```markdown

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

![呈现为两个相等列的 GitHub Markdown 表的屏幕截图。 标题以粗体呈现，备用内容行具有灰色底纹。](/assets/images/help/writing/table-basic-rendered.png)

桌子的两端的管道是可选的。

单元格的宽度可以不同，无需在列内准确对齐。 表头行的每一列中必须至少有三个连字符。

```markdown
| Command | Description |
| --- | --- |
| git status | List all new or modified files |
| git diff | Show file differences that haven't been staged |
```

![具有不同宽度的两列的 GitHub Markdown 表的屏幕截图。 行用于列出命令“git status”和“git diff”及其说明。](/assets/images/help/writing/table-varied-columns-rendered.png)

如果经常编辑代码片段和表，则可能受益于在 GitHub 上启用对所有注释字段采用固定宽度字体。 有关详细信息，请参阅“[关于在GitHub上撰写和格式化](/zh/enterprise-cloud@latest/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/about-writing-and-formatting-on-github#enabling-fixed-width-fonts-in-the-editor)”。

## 格式化表格中的内容

可以在表格中使用[格式](/zh/enterprise-cloud@latest/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)，例如链接、内联代码块和文本样式：

```markdown
| Command | Description |
| --- | --- |
| `git status` | List all *new or modified* files |
| `git diff` | Show file differences that **haven't been** staged |
```

![显示为代码块格式命令的 GitHub Markdown 表格截图。 说明中使用粗体和斜体格式。](/assets/images/help/writing/table-inline-formatting-rendered.png)

可以通过在标题行中连字符的左侧、右侧或两侧添加冒号 `:`，来靠左、靠右或居中对齐列中的文本。

```markdown
| Left-aligned | Center-aligned | Right-aligned |
| :---         |     :---:      |          ---: |
| git status   | git status     | git status    |
| git diff     | git diff       | git diff      |
```

![在 GitHub 中显示的三列 Markdown 表格的屏幕截图，展示了如何将单元格中的文本设置为左对齐、居中或右对齐。](/assets/images/help/writing/table-aligned-text-rendered.png)

若要包含竖线 `|` 作为单元格中的内容，请在竖线前使用 `\`：

```markdown
| Name     | Character |
| ---      | ---       |
| Backtick | `         |
| Pipe     | \|        |
```

![在 GitHub 上呈现的 Markdown 表格截图，展示了通常用于结束单元格的竖线（pipe）在前面加上反斜杠时如何显示。](/assets/images/help/writing/table-escaped-character-rendered.png)

## 其他阅读材料

* [
  GitHub 扩展 Markdown 规范](https://github.github.com/gfm/)
* [基本写作和格式语法](/zh/enterprise-cloud@latest/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)