Left-align headers 在 Markdown table 中?

Left-align headers in Markdown table?

使用 GitHub 上“Markdown Cheatsheet”中的 table 示例,您会得到:

| Tables        | Are           | Cool  |
| ------------- |:-------------:| -----:|
| col 3 is      | right-aligned | 00 |
| col 2 is      | centered      |    |
| zebra stripes | are neat      |     |

我的问题是,有什么方法可以 left-align header 个细胞吗?

这取决于您使用的实现方式。

表格是 Markdown 的一项 non-standard 功能,支持它们的每个实现方式都不同。例如问题中指向的"cheetsheet"在Markdown Here项目中。该项目的自述文件包括以下解释:

To discover what can be done with Markdown in Markdown Here, check out the Markdown Here Cheatsheet and the other wiki pages.

所以 "cheetsheet" 是特定于 Markdown Here 使用的实现。

GitHub 有 documented their implementation of Markdown as an extension of the Commonmark spec (Commonmark is a Markdown variant which does not support tables). According to example 192,列 headers 接收与列单元格相同的对齐方式:

| abc | defghi |
:-: | -----------:
bar | baz

<table>
<thead>
<tr>
<th align="center">abc</th>
<th align="right">defghi</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">bar</td>
<td align="right">baz</td>
</tr></tbody></table>

因此,您需要检查您正在使用的 Markdown 的具体实现并阅读该实现的文档。但是,就我个人而言,我从来没有遇到过允许您为单元格中的 headers 定义单独对齐方式的实现。根据我的经验,要么你得到 headers 匹配单元格,要么 headers 没有分配对齐。

在第二行,我将更改为将所有内容(headers 和内容)左对齐:

| :------------ | :-------------- | :----- |

注意每列左侧的冒号。


降价:

| Tables        | Are           | Cool  |
|:------------- |:-------------:| -----:|
| col 3 is      | right-aligned | 00 |
| col 2 is      | centered      |    |
| col 1 is      | left-aligned  |    |
| zebra stripes | are neat      |     |

结果:

Tables Are Cool
col 3 is right-aligned 00
col 2 is centered
col 1 is left-aligned
zebra stripes are neat

请注意第二行的冒号(“:”)和第二个字符 另一种选择是将数字移动到 left-most 列(如下所示)

Amount | Items
------:|:-----
    20 | Wooden Boards
     5 | Old Parts

StackEdit 上试用。

将 ---- 行放在 headers 上方似乎不起作用。