我有一张表:
| This | Is | A | Table |
| :--- | -- | - | ----: |
| foo | ba | r | elbaT |
我希望表格能够居中显示在我的Markdown文件中,而不是左对齐。 我不是想要对齐文本,而是整个表格本身。 我需要使用HTML / CSS才能实现我想要的效果吗?
这是为Apiary.io项目准备的。
我有一张表:
| This | Is | A | Table |
| :--- | -- | - | ----: |
| foo | ba | r | elbaT |
我希望表格能够居中显示在我的Markdown文件中,而不是左对齐。 我不是想要对齐文本,而是整个表格本身。 我需要使用HTML / CSS才能实现我想要的效果吗?
这是为Apiary.io项目准备的。
如果您使用标准文档,请像这样使用<center>
标签。
FORMAT: 1A
HOST: http://www.google.com
# Tables
Notes API is a *short texts saving* service similar to its physical paper presence on your table.
<center>
| Tables | Are | Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
</center>
# Group Notes
(...)
如果您使用“新文档”,则不可能将表格居中显示(因为表格占用了整个列的宽度)。
一个简单的方法似乎被大家忽视了,就是将表格包含在一个 div
中,并在其上使用 align="center"
属性。
<div align="center">
| Tables | Are | Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
</div>
像<center>
一样工作。 不需要再担心<center>
被弃用了。 ;)
<div align="center">
。 - Rohan Lekhwanialign
属性也已被弃用。 - undefined是的。您可以在API Blueprint中使用GFM表格——请查看http://docs.tables.apiary.io,以获取下面蓝图源代码的呈现版本。
FORMAT: 1A
# Tables API
Note: Tables can be handcrafted or generated at <http://www.tablesgenerator.com/markdown_tables>.
## Table 1
**Discussion option 1**
| Tables | Are | Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
# Message [/pages]
## Create a Message [POST]
### Table 2
**Discussion option 2**
| Tables | Are | Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
+ Request (application/json)
## Table 3
**Discussion option 3**
| Tables | Are | Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
+ Headers
Authorization:Bearer tokenString
+ Body
{ ... }
+ Response 201
Gaffney在Apiary.io问题评论中详细介绍了我的解决方案。
基本上,我在apiary.apib HTML块中添加自定义样式表和脚本,使用HTML来为页面设置样式,而不是使用Markdown dialect作为CSS。
从 Yihui 的书中(https://bookdown.org/yihui/rmarkdown-cookbook/kable.html) 关于 kable()
:
当表格包含标题时,它们默认居中对齐。如果您不想让表格居中,请使用 centering = FALSE 参数。