Is it possible to center tables in a markdown file?

MarkdownGithub Flavored-MarkdownApiblueprintapiary.io

Markdown Problem Overview


I have a table:

    | This | Is | A | Table |
    | :--- | -- | - | ----: |
    | foo  | ba | r | elbaT |

I'd like the table to display in the center of my Markdown file instead of left-aligned. I am not trying to align text, but the entire table itself. Do I need to resort to HTML/CSS to achieve what I want?

This is for an Apiary.io project.

Markdown Solutions


Solution 1 - Markdown

If you use the standard documentation, use the <center> tag like so.

Blueprint
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

(...)
Preview


If you use the New Documentation, it's not possible to center a table (since the table takes a full width of the column).

Preview

Solution 2 - Markdown

It is simple. As you know the "|-|" is used for indicate the table and ":" is used for indicate the text alignment. If |:-| entered that is a right aligned text column. If |-:| entered that is a left aligned text and if |:-:| entered that is a centre aligned.

Solution 3 - Markdown

Yes. You can have GFM tables in API Blueprint – check <http://docs.tables.apiary.io> for rendered version of the blueprint source bellow.

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

Solution 4 - Markdown

A simple method that everyone seems to have overlooked is to enclose the table within a div and use the align="center" property on it.

<div align="center">

| Tables   |      Are      |  Cool |
|----------|:-------------:|------:|
| col 1 is |  left-aligned | $1600 |
| col 2 is |    centered   |   $12 |
| col 3 is | right-aligned |    $1 |

</div>

Works just like <center> used to. No need to worry about <center> getting deprecated anymore. ;)

Solution 5 - Markdown

My solution detailed by Gaffney in an Apiary.io issue comment.

Basically I add custom stylesheets and scripts within apiary.apib HTML blocks to style the page with HTML instead of headwalling that a Markdown dialect isn't CSS.

Also "How to Center Anything in CSS".

Solution 6 - Markdown

From Yihui's book(<https://bookdown.org/yihui/rmarkdown-cookbook/kable.html>;) re: kable():

> Tables are center-aligned by default when they are included in a table environment (i.e., when the table has a caption). If you do not want to center a table, use the argument centering = FALSE.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMeredithView Question on Stackoverflow
Solution 1 - MarkdownBaggzView Answer on Stackoverflow
Solution 2 - Markdownyashod pereraView Answer on Stackoverflow
Solution 3 - MarkdownZdenekView Answer on Stackoverflow
Solution 4 - MarkdownRohan LekhwaniView Answer on Stackoverflow
Solution 5 - MarkdownMeredithView Answer on Stackoverflow
Solution 6 - Markdownpdw5View Answer on Stackoverflow