跳至主要内容

使用表格组织信息

您可以构建表格来组织评论、问题、拉取请求和 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.

进一步阅读