11

I want to use a table in my answer.
e.g

|-------------|----------------|
| ShortCut | Description |
|-------------|----------------|

I have posted an answer here, which requires this kind of formatting.

Is it possible to have such formatting in stackoverflow Questions & answers ?

  • If yes, How ?
  • If no, why ?

Edit : I tried to use following code directly in editor of SO. But it didn't work for me.

<table>
<tr>
<td>hello</td>
<td>hello2</td>
</tr>
<tr>
<td>hello3</td>
<td>hello4</td>
</tr>
</table>
2
  • 2
    Your answer is here: webapps.stackexchange.com/questions/6700/… first answer links to a website that will do this for you.
    – user1228
    Commented Jul 1, 2011 at 13:42
  • Not a duplicate of that question. This question is about tables -- that question is about ASCII tables. Commented Apr 29, 2016 at 21:46

3 Answers 3

7

Standard Markdown should have allowed in-lined HTML table. However, seems it's not supported by SE's implementation of Markdown.

There are currently few Markdown implementation, which do support tables syntax originally created for PHP Markdown Extra.

Tables in above syntax have source like this:

| Left align | Right align | Center align |
|:-----------|------------:|:------------:|
| This       |        This |     This     |
| column     |      column |    column    |
| will       |        will |     will     |
| be         |          be |      be      |
| left       |       right |    center    |
| aligned    |     aligned |   aligned    |

And are rendered as HTML table, which looks like this:

rendered table

Example table is from this Python implementation.

4

You can use Unicode characters. For example:

                   [My DataTabel]                                     
  ┌───────────┬───────────┼───────────┬───────────┐
  │  Field#1  │  Field#2  │    ∙∙∙    │  Field#n  │
  ├───────────┼───────────┼───────────┼───────────┤
  │ Data[1-1] │ Data[1-2] │    ∙∙∙    │ Data[1-n] │
  ├───────────┼───────────┼───────────┼───────────┤
  │ Data[2-1] │ Data[2-2] │    ∙∙∙    │ Data[2-n] │
  ├───────────┼───────────┼───────────┼───────────┤
  │    ∙∙∙    │    ∙∙∙    │    ∙∙∙    │    ∙∙∙    │
  ├───────────┼───────────┼───────────┼───────────┤ 
  │ Data[m-1] │ Data[m-2] │    ∙∙∙    │ Data[m-n] │ 
  └───────────┴───────────┴───────────┴───────────┘ 
2
  • Those are box-drawing characters, not 7-bit ASCII characters. Commented Nov 5, 2017 at 0:49
  • 1
    updated to unicode
    – Mehdi
    Commented Nov 5, 2017 at 6:12
3

I fail to see why a table is needed for that answer.

But if you want to create a table, your best bet is to use the one you've posted in code tags:

|-------------|----------------|
| ShortCut    | Description    |
|-------------|----------------|

This could also be extended with Unicode.

It does not support extended formatting, though.

4
  • does <code> tag supports <kbd> tag within it ? Commented Jul 1, 2011 at 11:01
  • @sugar: No, I don't think so. Commented Jul 1, 2011 at 11:01
  • I posted the link to my answer just because I want to give some Idea of a case where Table is very necessary to demonstrate neat & sharp. Commented Jul 1, 2011 at 11:04
  • Note that the mobile theme uses wrapping, not scrolling. Makes ASCII tables look very bad.
    – Arjan
    Commented Aug 4, 2012 at 12:29

Not the answer you're looking for? Browse other questions tagged .