Centering a table in .md file not working

I am trying to center a table in .md file, for a Hugo theme (casper).
I use the usual table format as:

| Header One     | Header Two     |
| :------------- | :------------- |
| Item One       | Item Two       |

this is left aligned, as shown here.

If I use:

<center>
    | Header One     | Header Two     |
    | :------------- | :------------- |
    | Item One       | Item Two       |
 </center>

then the table is not shown correctly, as shown here:

How can I center a table in a .md file? I want to center the whole table, not just the table elements.

Thanks for your help.

Last version of mmark render support this feature, but Hugo no longer updates mmark module.

Mikhail: thanks for the answer. Does it mean there is no solution?

You can inset pure HTML in markdown.

Can you please elaborate?

For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags.

For example, to add an HTML table to a Markdown article:

This is a regular paragraph.

<table>
    <tr>
        <td>Foo</td>
    </tr>
</table>

This is another regular paragraph.

https://daringfireball.net/projects/markdown/syntax#html

I put the HTML table as this inside the .md file:

<center>
    <table>
        <tr>
            <td>Foo1</td> <td>Foo2</td>
        </tr>
    </table>
</center>

But the table is not horizontally centered.

google: inline css

I did and followed the instructions, but nothing is working :frowning:

http://www.tablesgenerator.com/html_tables

1 Like

Perfect, it works great :slightly_smiling:

  1. You can use a shortcode if you want to wrap markdown in HTML. This has pros and cons; namely, the pro is that it’s cleaner and easier to manage and repurpose, while the con is that the shortcodes are pretty Hugo specific.
  2. Your original issue has very little to do with Hugo, just as an FYI: HTML-wrapped markdown is not rendered as markdown according to the spec.

Of course, you can just write flat HTML inside your markdown files as well, as already mentioned :smile: Throwing this out there in hope that it helps…

1 Like

@rdwatters thank you very much, yes that is very helpful.

I looked into the Hugo issues (open and closed) but cannot really see why this is the case. Can someone from the Hugo team comment on this? ‘no longer being updated’ seems the first step to sunsetting this feature.

Just wonder if it still makes sense to convert to mmark. Don’t want to be reconverting my content at a later point. :slight_smile:

Developers use Hugo for small blogs primarily, and are not interested in the functionality for extended formatting.

I don’t use mmark. But for curiosity, is this official? If so, I’d be glad to take if off my checklist (working on an Org to ‘Markdown for Hugo’ exporter package).

MMARK twice more advanced render, compared with BlackFriday, and as fast as BlackFriday. I do not know why it is used so little.


I’m not a developer so I’m more guessing (due to no answer yet), but if I look at the vendor file in Hugo’s source code, I see that mmark from May 19 is used. (That’s how interpret it that .json file.)

That would match mmark release 1.3.5, which is one small version (0.0.1) behind the latest mmark release (1.3.6). I guess that Hugo bumps up the mmark version in the next non-bug fix release.

It can also mean that the May 19 comment that ‘Hugo doesn’t update mmark anymore’ is not accurate anymore. (Although it hasn’t been disputed by a developer either.)

Would love to hear some clarification instead of using my own uneducated guesses. :slight_smile: