跳至主要内容

使用表格组织信息

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

创建表格

您可以使用管道 | 和连字符 - 创建表格。连字符用于创建每个列的标题,而管道用于分隔每列。为了使表格正确渲染,您必须在表格之前包含一个空行。


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

Screenshot of a Markdown table with two columns of equal width as rendered on GitHub. Headers render 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 Markdown table with two columns of differing width as rendered on GitHub. 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 Markdown table with two columns of differing width as rendered on GitHub. The commands "git status" and "git diff" are formatting as code blocks.

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

| 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, can display inside cells when prefaced by a backslash.

进一步阅读