跳至主要内容

使用表格组织信息

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

谁可以使用此功能?

Markdown 可在 GitHub 网页界面中使用。

创建表格

您可以使用管道符 | 和连字符 - 创建表格。连字符用于创建每列的表头,而管道符分隔各列。您必须在表格前加一个空行,以便正确渲染。


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

Screenshot of a GitHub Markdown table rendered as two equal columns. Headers are shown in boldface, and alternate content rows have gray shading.

表格两端的管道符是可选的。

单元格的宽度可以不同,不需要在列内完美对齐。表头行的每一列必须至少有三个连字符。

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

Screenshot of a GitHub Markdown table with two columns of differing width. Rows list the commands "git status" and "git diff" and their descriptions.

如果您经常编辑代码片段和表格,启用 GitHub 所有评论字段的等宽字体可能会对您有所帮助。更多信息,请参阅 关于在 GitHub 上编写和格式化

在表格中格式化内容

您可以在表格中使用 格式化,例如链接、内联代码块和文本样式

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

Screenshot of a GitHub Markdown table with the commands formatted as code blocks. Bold and italic formatting are used in the descriptions.

您可以通过在表头行的连字符左侧、右侧或两侧添加冒号 :,将文本左对齐、右对齐或居中对齐。

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

Screenshot of a Markdown table with three columns as rendered on GitHub, showing how text within cells can be set to align left, center, or right.

要在单元格内容中包含管道符 |,请在管道符前使用 \

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

Screenshot of a Markdown table as rendered on GitHub showing how pipes, which normally close cells, are shown when prefaced by a backslash.

延伸阅读

© . This site is unofficial and not affiliated with GitHub, Inc.